I am working with the following:
#include <stdio.h>
int main()
{
int pid, i;
pid = vfork();
switch(pid)
{
case -1: /* an error occurred */
printf("Fork error");
break;
case 0: /* this code is executed by the child process */
for(i=1; i<10000; i++)
printf("Child process, iteration: %d\n", i);
break;
default: /* this code is executed by the parent process */
for(i=1; i<10000; i++)
printf("Parent process, iteration: %d\n", i);
}
}
The idea is to have the child process finish all of its work and then the parent process starts printing. When I upload the file to the server, compile and run it, it only seems to run the child process and then errors out. I receive the following:
...
child process, iteration: 9995
child process, iteration: 9996
child process, iteration: 9997
child process, iteration: 9998
child process, iteration: 9999
Segmentation fault (core dumped)
So, my question is why does the parent process not start after the child process has finished? I'm probably missing something very obvious here...
Thank you very much in advance for any and all comments/suggestions.

New Topic/Question
Reply




MultiQuote




|