blob: e698d9634bafc096995ab1a482d00a82a7d5ae57 [file] [log] [blame]
<html lang="en">
<head>
<title>Concepts of Job Control - The GNU C Library</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="The GNU C Library">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Job-Control.html#Job-Control" title="Job Control">
<link rel="next" href="Job-Control-is-Optional.html#Job-Control-is-Optional" title="Job Control is Optional">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This file documents the GNU C library.
This is Edition 0.12, last updated 2007-10-27,
of `The GNU C Library Reference Manual', for version
2.8 (Sourcery G++ Lite 2011.03-41).
Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002,
2003, 2007, 2008, 2010 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Free Software Needs Free Documentation''
and ``GNU Lesser General Public License'', the Front-Cover texts being
``A GNU Manual'', and with the Back-Cover Texts as in (a) below. A
copy of the license is included in the section entitled "GNU Free
Documentation License".
(a) The FSF's Back-Cover Text is: ``You have the freedom to
copy and modify this GNU manual. Buying copies from the FSF
supports it in developing GNU and promoting software freedom.''-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
<link rel="stylesheet" type="text/css" href="../cs.css">
</head>
<body>
<div class="node">
<a name="Concepts-of-Job-Control"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Job-Control-is-Optional.html#Job-Control-is-Optional">Job Control is Optional</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Job-Control.html#Job-Control">Job Control</a>
<hr>
</div>
<h3 class="section">27.1 Concepts of Job Control</h3>
<p><a name="index-shell-3200"></a>The fundamental purpose of an interactive shell is to read
commands from the user's terminal and create processes to execute the
programs specified by those commands. It can do this using the
<code>fork</code> (see <a href="Creating-a-Process.html#Creating-a-Process">Creating a Process</a>) and <code>exec</code>
(see <a href="Executing-a-File.html#Executing-a-File">Executing a File</a>) functions.
<p>A single command may run just one process&mdash;but often one command uses
several processes. If you use the &lsquo;<samp><span class="samp">|</span></samp>&rsquo; operator in a shell command,
you explicitly request several programs in their own processes. But
even if you run just one program, it can use multiple processes
internally. For example, a single compilation command such as &lsquo;<samp><span class="samp">cc
-c foo.c</span></samp>&rsquo; typically uses four processes (though normally only two at any
given time). If you run <code>make</code>, its job is to run other programs
in separate processes.
<p>The processes belonging to a single command are called a <dfn>process
group</dfn> or <dfn>job</dfn>. This is so that you can operate on all of them at
once. For example, typing <kbd>C-c</kbd> sends the signal <code>SIGINT</code> to
terminate all the processes in the foreground process group.
<p><a name="index-session-3201"></a>A <dfn>session</dfn> is a larger group of processes. Normally all the
processes that stem from a single login belong to the same session.
<p>Every process belongs to a process group. When a process is created, it
becomes a member of the same process group and session as its parent
process. You can put it in another process group using the
<code>setpgid</code> function, provided the process group belongs to the same
session.
<p><a name="index-session-leader-3202"></a>The only way to put a process in a different session is to make it the
initial process of a new session, or a <dfn>session leader</dfn>, using the
<code>setsid</code> function. This also puts the session leader into a new
process group, and you can't move it out of that process group again.
<p>Usually, new sessions are created by the system login program, and the
session leader is the process running the user's login shell.
<p><a name="index-controlling-terminal-3203"></a>A shell that supports job control must arrange to control which job can
use the terminal at any time. Otherwise there might be multiple jobs
trying to read from the terminal at once, and confusion about which
process should receive the input typed by the user. To prevent this,
the shell must cooperate with the terminal driver using the protocol
described in this chapter.
<p><a name="index-foreground-job-3204"></a><a name="index-background-job-3205"></a>The shell can give unlimited access to the controlling terminal to only
one process group at a time. This is called the <dfn>foreground job</dfn> on
that controlling terminal. Other process groups managed by the shell
that are executing without such access to the terminal are called
<dfn>background jobs</dfn>.
<p><a name="index-stopped-job-3206"></a>If a background job needs to read from its controlling
terminal, it is <dfn>stopped</dfn> by the terminal driver; if the
<code>TOSTOP</code> mode is set, likewise for writing. The user can stop
a foreground job by typing the SUSP character (see <a href="Special-Characters.html#Special-Characters">Special Characters</a>) and a program can stop any job by sending it a
<code>SIGSTOP</code> signal. It's the responsibility of the shell to notice
when jobs stop, to notify the user about them, and to provide mechanisms
for allowing the user to interactively continue stopped jobs and switch
jobs between foreground and background.
<p>See <a href="Access-to-the-Terminal.html#Access-to-the-Terminal">Access to the Terminal</a>, for more information about I/O to the
controlling terminal,
</body></html>