if you don't call exit(), the compiler will insert it.
try running under 'strace' and you'll see the exit().


ANDY wrote:
> 
> hey all !
> 
> I am a little confused about process creation and termination.
> I think I'll just provide example code to stress my question.
> 
> ------------------------------------------
> int main(){
> 
> int child_pid;
> 
>  if( (child_pid = fork()) == -1 )
>    perror("cannot fork\n");
> 
>  else if(child_pid){    /* parent */
>         if(wait(NULL) == -1)
>                 perror("can't wait\n");
>         printf("parent\n");
>  }
> 
>  else{                  /* child */
> 
>         printf("child process\n");
>         /* exit(0); */
>  }
> 
> }
> ----------------------------------------------------
> I guess my questions were:
> 1. why doesn't " the exit(0) statement ( that is commented ) "
> make any difference ?
> 
> If I understand it right.  A process will terminate by the call
> to exit(status) system call.  And status will be
> passed to the parent via the wait() syscall with an argument that is not
> NULL. which leads to my other question
> 
> 2.can a newly created process( in my program is the child )
> be terminated if there is no more instruction to execute which in my case
> the else block statement only has one printf statement ?
> eg: else{ printf("foo\n"); }
> 
> 3.Does it also imply that a newly created process can be terminated
> WITHOUT calling exit() or catching some other "terminating" signals
> from the kernel ?
> 
> thanks folks
> 
> --truly deeply curious
>         Andy ------

-- 
Christoph Bugel         [EMAIL PROTECTED]

Reply via email to