Hi,
This is the man page for fork:
Upon successful completion, the fork() and vfork() functions return a value
of 0 (zero) to the child process and return the process ID of the child
process to the parent process. Otherwise, a value of -1 is returned to the
parent, no child process is created, and errno is set to indicate the
error.
so, if ( !fork() ) is saying if the return code from the fork command is
NOT (!) 0, then do whats between the braces. In other words, only run the
code between {} if it is the parent process.
A lot of times you will see it coded like this:
pid = fork();
if (!pid)
{
}
Good luck!
John Gorman
On 17 Jun 98, at 1:52, Jeff wrote:
> 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
>
///
(. .)
/=====oOO-(_)-OOo===========================\
/ \
/ John Gorman \
| E-mail: [EMAIL PROTECTED] |
| |
\ "We are what we repeatedly do." /
\ Aristotle /
\===========================================/