how to send process to background and foreground using a system or lib function?

how to send process to background and foreground using a system or lib function?

Post by Richard Li » Fri, 22 Sep 2000 04:00:00



how to send process to background and foreground using a system or lib
function?
please advice.

regards,
richard lim

 
 
 

how to send process to background and foreground using a system or lib function?

Post by Derek M. Fly » Fri, 22 Sep 2000 04:00:00



> how to send process to background and foreground using a system or lib
> function?

The "right way" to do this is with threads.  But if you just want to start
something, then stop it, restart it, etc., you can fork and exec your new
process, and send STOP and CONT signals to it whenever you please.

 
 
 

how to send process to background and foreground using a system or lib function?

Post by Kaz Kylhe » Fri, 22 Sep 2000 04:00:00



>how to send process to background and foreground using a system or lib
>function?

That depends on what you mean by foreground or background. In UNIX, the terms
foreground and background formally apply to jobs running under a controlling
terminal. In a terminal session, there are one or more process groups. One of
these (at a time) is the foreground process group; it can receive input and
send output to the terminal.  Other jobs are background process groups. The
shell controls who gets to be the foreground process group. When you type
Ctrl-Z (or whatever your configured suspend key is), the foreground process
group gets the SIGTSTP signal, generated by the terminal driver. The shell
detects this change of state and makes itself the foreground process group. You
now interact with the shell.  Using the shell's ``fg'' command, you can select
one of the background jobs to become the foreground process group.

There is no point in messing with any of this, just let the user have the
control.  One thing that sometimes makes sense to implement in a terminal-based
application is a suspend command which ``artificially'' raises SIGTSTP within
that process. You need to do this if you put the tty in raw mode, so that
Ctrl-Z is not interpreted by the driver, and the user otherwise has no way
to suspend.

--
Any hyperlinks appearing in this article were inserted by the unscrupulous
operators of a Usenet-to-web gateway, without obtaining the proper permission
of the author, who does not endorse any of the linked-to products or services.