plz help!

i'm pretty new to unix programming. i just wanna know how exactly fork(), waitpid() works. i have read some from the book, but it's still confusing. especially with those < 0 and == 0. plz help!!!!

try this code for fork
#include <stdio.h>
void main()
{

int i ;

printf("The pid of the parent is :%d \n",getpid());

i = fork();
if ( i == 0 )
{
printf("The child pid is :%d and the parent pid is :%d \n",getpid(),getppid());
}
else
{
printf("The parent pid is :%d\n",getpid());
}
}

when a fork is called then the successfull return value of the fork is 0 , the 0 return value is the child process , you will see that when the return value is compared with 0 the child part of the code is executed which is inside the if loop , otherwise the parent is executed( which is the else part)
The child process after fork will always get the value 0.

If you have used fork then child and parent is created.
If inside the child part of code you have written waitpid("parent pid"){waitpid(getppid())} then the child will wait for the parent to be finish. When the parent will complete then the child will start to execute.
If you used like waitpid("child pid") inside the parent part of code then the parent will wait till the child is finished.

Rajesh