putting C programs in the background

Ron Natalie <ron> ron at brl-tgr.ARPA
Fri Jan 18 11:07:47 AEST 1985


> This is a continuation of the last article(Sorry).
> 
> Can a program put another program into the background given its
> pid.     |
>          +-----> Not a supervisory or parent .
> 
> 						Mark

In the genereal case no. The problem that people here have a hard
time coping with is that "BACKGROUND" is not a characturistic of
a UNIX process.  BACKGROUND happens when your shell decides not to
wait for a process to finish.  There is nothing you can do to the
process itself to make this happen, what you have to do is do something
to the parent to make it stop waiting.

In 4.2 they handle this by putting special code in the shell.  Sending
a certain signal to a process causes it to enter a special "STOP" state
and the parent gets an answer to it's wait call (similar to the way PTRACE
operates).  The parent can then CONTINUE the process without waiting for
it to finish, i.e. putting it in the background.  It can also CONTINUE it
and wait, i.e. leave it in the forground.  If you are clever in what you
do with file descriptors and process groups you can even move background
processes to the foreground.

Detesting the CSH, I now have a 5R2 bourne shell running on 4.2 BSD that
supports the above feature.

-Ron



More information about the Comp.lang.c mailing list