Restarting forked child

Hello everyone!

I have to complete a project for school about Unix programming.

I have to create some forked child-processes and each one of them has to start a shell.

What the project asks is to check if any of the child processes (the shells) is terminated while the father is still running and, if so, restart it.

How do i check if the process is closed and how do i restart it?



Thank you very much in advance :-)
See waitpid()
how can i implement it?

1
2
3
4
5
6
7
8
9
10
11
pid = fork()
if (pid == 0)
{  
  //child operations

}

else {
  //father operations

}





Thx by the way for your answer
How can i add the part where i check if the child has been closed and restart it?
The psuedo code looks something like:
1
2
3
4
5
6
7
8
keeprunning := true
fork()
if child:
  while keeprunning
    exec shell
    use waitpid to wait for shell to terminate
   endwhile
endif

Topic archived. No new replies allowed.