< Previous | Contents | Next >
Putting A Process In The Background
Let's say we wanted to get the shell prompt back without terminating the xlogo pro-
gram. We can do this by placing the program in the background. Think of the terminal as having a foreground (with stuff visible on the surface like the shell prompt) and a back- ground (with stuff hidden behind the surface). To launch a program so that it is immedi- ately placed in the background, we follow the command with an “&” character:
[me@linuxbox ~]$ xlogo &
[1] 28236
[me@linuxbox ~]$
[me@linuxbox ~]$ xlogo &
[1] 28236
[me@linuxbox ~]$
After entering the command, the xlogo window appeared and the shell prompt returned, but some funny numbers were printed too. This message is part of a shell feature called job control. With this message, the shell is telling us that we have started job number 1 (“[1]”) and that it has PID 28236. If we run ps, we can see our process:
[me@linuxbox ~]$ ps
PID TTY TIME CMD
10603 pts/1 00:00:00 bash
28236 pts/1 00:00:00 xlogo
28239 pts/1 00:00:00 ps
[me@linuxbox ~]$ ps
PID TTY TIME CMD
10603 pts/1 00:00:00 bash
28236 pts/1 00:00:00 xlogo
28239 pts/1 00:00:00 ps
The shell's job control facility also gives us a way to list the jobs that have been launched from our terminal. Using the jobs command, we can see this list:
[me@linuxbox ~]$ jobs
[1]+ Running
xlogo &
[me@linuxbox ~]$ jobs
[1]+ Running
The results show that we have one job, numbered “1”, that it is running, and that the com- mand was xlogo &.