> 1 is main() 'the' initial parent process
main is what the C runtime library calls at the end of it's initialisation. It marks the start of your code.
Code:
void myfunc ( ) {
printf( "hello world\n" );
}
int main ( ) {
myfunc();
return 0;
}
myfunc isn't a process any more than main is. A single process exists sometime before main is called until sometime after main returns. Everything in between is all the same process.
> ie when i call getppid() is that returning a reference to mains process ?
No, it's the ID of the thing which ran it.
If you double-clicked on an executable, then getpid() would be yourself, and getppid() would be explorer.
> 2 when i call fork() is that the only time that a child process is created ?
Yes (well, mostly).
> 3 how do you tell when a child process has ended
Those you've listed are good methods.
Or write a signal handler for SIGCHLD