Starting and stopping a forked process

Is it possible for a parent process to start and stop a child (forked) process on Unix?

I want to implement a task scheduler ( see here ) that can run multiple processes at the same time, which in my opinion requires separate processes or threads.

How do I stop the execution of the child process and resume it after a given amount of time?

(If this is only possible with streams, how are streams implemented?)

0


source to share


3 answers


You can write a simple simulated scheduler using signals. If you have permission, the SIGSTOP signal stops the process, and the SIGCONT signal continues.

With signals, you won't have any fine-grained control over "scheduling", but I think the OS-rank scheduler is not the target of this execersice in any way.



Check the delete (2) and alarm (7) pages manually. There are also many tutorials on using Unix signals on the Internet.

+2


source


You can use signals, but in the normal UNIX world it is probably easier to use semaphores. Once you've set a semaphore to keep another process out, the scheduler will replace it in the normal course of things; when you clear the semaphore, it will be ready to run again.



You can do the same with streams, of course; the only dramatic difference is that you keep the heavyweight context switch.

+1


source


Just a side note: if you use signal (), the behavior may differ on different Unixes. If you are using Linux, check the Portability section of the man page and your preferred sigaction man page.

0


source







All Articles