Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Dec 2002 10:51:43 +0100 (MET)
From:      Paul Everlund <tdv94ped@cs.umu.se>
To:        Aaron Burke <aburke@nullplusone.com>
Cc:        freebsd-questions@freebsd.org
Subject:   RE: Problems with a C application that changes users and run 'screen -x'
Message-ID:  <Pine.GSO.4.44.0212201041270.19542-100000@kvist.cs.umu.se>
In-Reply-To: <NGBBLCIHCLNJAIGIFFHJIEAPCPAA.aburke@nullplusone.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 20 Dec 2002, Aaron Burke wrote:

> > 3. Avoid using system() which I vaguely recall being described with a
> >    lot of bad words in various places and use fork(), exec(), _exit(),
> >    waitpid() and exit() instead.
>
> How would I do this with exec. According to the man page for exec
> I have only a few options.
>      int execl(const char *path, const char *arg, ...);
>      int execlp(const char *file, const char *arg, ...);
>      int execle(const char *path, const char *arg, ...);
>      int exect(const char *path, char *const argv[],
> 		   char *const envp[]);
>      int execv(const char *path, char *const argv[]);
>      int execvp(const char *file, char *const argv[]);
>
> Can you point me to the right documentation to learn about
> the exec functions provided by <unistd.h>?
>
> Allthough I am not familiar with unistd.h at all, I did do
> a little bit of expermentation.
>
> Here is my new code:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
>
> int main(int argc, char* pszArgs[])
> {
>         int result, result2;
>         result= execlp("/usr/bin/su", "ppp", "-m");
>         result2=execlp("/usr/local/bin/screen", "-x");
>         return result + result2;
> }
> bash-2.05$ g++ run-ppp.c
> bash-2.05$ ./a.out
> bash-2.05$
>
> I am a little supprised that nothing appeared to have happened.
> Perhaps I am running these improperly. Am I using the correct
> exec command? Can you demonstrate how this should work?
> What else could execlp(args) needs to say?
>
> >
> > - Giorgos
> >
>
> Thanks for your time.

I think execlp is writing over your current process. So first your
process is exchanged with ppp, then ppp is exchanged with screen. You
have to make a copy of your current process, a.out, by using fork, and
then exchange the process image in this copy using execlp.

I suggest you read more about those functions Giorgos mentioned: fork,
execlp, waitpid, and exit.

Best regards,
Paul


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.44.0212201041270.19542-100000>