Tom Duerbusch writes:
> I have a process that may or may not be running in background.
>
> When I use any of the forms of "ps", it shows the process running, but, I 
> don't understand if any of the fields being displayed, indicate that this is 
> a BG process.  It all looks the same to me <G>.
>
> If the process is running in the background, I need to follow the path of how 
> did it get there (bg).  If the process isn't running in background, I have a 
> different problem all together.

Use the "-j" or "j" option of ps to list the process group,
session ID and controlling terminal of your processes. So if you
prefer your ps options SysV-flavoured, do
    ps -ejww
or if you prefer them BSD-flavoured, do
    ps ajxww
You may be able to get way without knowing the precise details of how
processes, process groups, sessions and controlling terminals interact.
The common cases are
(1) The process is a daemon: no controlling terminal (TTY column "?"),
    pid = pgid = sid.
(2) The process is an interactive shell: has a controlling terminal,
    pid = pgid = sid.
(3) The process is a part of a foreground or background job of an
    interactive shell: has a controlling terminal (that of the shell
    that started the job), sid is same as the shell's sid.
    The leader of the process group (pid = pgid) is usually the first
    command in a pipe line (e.g. for a | b | c, the pgid will be the
    pid of a and b and c will have same pgid but, of course, different
    pids).
The difference between "foreground" and "background" is whether the
pgid is the one set on the controlling terminal. The shell uses
tcsetpgrp() on the controlling terminal to switch between foreground
and background. The important consequences are things like hitting
Ctrl/C on the terminal sends an interrupt signal to its process
group (foreground processes) and processes attempting I/O to their
controlling terminal get refused with SIGTTOU sent if their process
group doesn't match (i.e. background processes), although that
behaviour is configurable.

--Malcolm

--
Malcolm Beattie
Mainframe Systems and Software Business, Europe
IBM UK

----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
----------------------------------------------------------------------
For more information on Linux on System z, visit
http://wiki.linuxvm.org/

Reply via email to