Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

When a command line with a pipe (|) is sent to the background, the PID of the last command in the

pipeline is
displayed.
All pipeline processes are members of that job.

[user@host ~]$ example_command | sort | mail -s "Sort output" &

[1] 5998

Use the jobs command to display the list of jobs for the shell's session.

[user@host ~]$ jobs

[1]+ Running sleep 10000 &

[user@host ~]$

Use the fg command to bring a background job to the foreground.


Use the the (%jobNumber) format to specify
the process to foreground.

[user@host ~]$ fg %1

sleep 10000

In the preceding example, the sleep command is running in the foreground on the controlling terminal.
The
shell itself is asleep and waiting for this child process to exit.

To send a foreground process to the background, press the keyboard-generated suspend request (Ctrl+z) in
the terminal.
The job is placed in the background and suspended.

[user@host ~]$ sleep 10000

^Z

[1]+ Stopped sleep 10000

[user@host ~]$

The ps j command displays information about jobs.


Use the ps j command to find process and session
information.

The PID is the unique process ID of the process.


The PPID is the PID of the parent process of this process, the process that started (forked) it.
The PGID is the PID of the process group leader, normally the first process in the job's pipeline.
The SID is the PID of the session leader, which (for a job) is normally the interactive shell that is running
on its controlling terminal.

In the next example, the sleep command is currently suspended and the process state is T.

[user@host ~]$ ps j

PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND

2764 2768 2768 2768 pts/0 6377 Ss 1000 0:00 /bin/bash

2768 5947 5947 2768 pts/0 6377 T 1000 0:00 sleep 10000

2768 6377 6377 2768 pts/0 6377 R+ 1000 0:00 ps j

Use the bg command with the job ID to start running the suspended process.

[user@host ~]$ bg %1

[1]+ sleep 10000 &

The shell warns a user who attempts to exit a terminal window (session) with suspended jobs.
If the user tries
again to exit immediately, then the suspended jobs are killed.

Note
In the previous examples, the + sign indicates that this job is the current default.
If a job-control
command is used without %jobNumber argument, then the action is taken on the default job.
The -
sign indicates the previous job that will become the default job when the current default job
finishes.

 
References
Bash info page (The GNU Bash Reference Manual) https://www.gnu.org/software/bash/manual

Section 7: Job Control

bash(1), builtins(1), ps(1), and sleep(1) man pages

Previous Next

You might also like