if ((pid = fork()) < 0) then forking process fails you must ensure you do
this check.
if (pid == 0) this is the child process were you invoke your child process
using execlp or what ever you wish
else your in the parent process.
Remember when your in the child process you must kill the child before
returning back to the parent process. You can use exit(1) or whatever takes
your fancy. Good Luck

Kind Regards
        Renato Parletta........

To reply send mail to:   [EMAIL PROTECTED]
                    ICQ No:   130789521

         "l can only assume that a "Do Not File" document
          is filed in a "Do Not File" file."

Senator Frank Church
Senate Intelligence Subcommittee Hearing, 1975




-----Original Message-----
From: Jeff <[EMAIL PROTECTED]>
To: linux-c-programming <[EMAIL PROTECTED]>
Date: Wednesday, June 17, 1998 6:42 PM
Subject: fork()


>Hello, I am trying to write a socket program to allow a program on another
>box to run ppp-on on this one without having to telnet into my linux box
>running ip_masq. My program basically goes like this:
>
>socket()
>bind()
>listen()
>and then an accept() loop that first blocks until it gets a connection,
>adn then runs this code:
>
>if (!fork())  // what does this line mean? if(fork == 0)?
>{
> send(new_fd, "hello\n", 6, 0);
> close(new_fd);
> while(waitpid(-1,NULL,WNOHANG) > 0);
>}
>
>this came from a socket tutorial, my actual code is a little different
>and includes a recv that prints the first thing it recieves and then
>continues, and it also has some error checking that I left out. I dont
>understand what this is doing. particularly how the fork() function works.
>Could someone explain this?
>
>Thanks,
>Jeff
>

Reply via email to