Linux: Job Control

By Xah Lee. Date: . Last updated: .

This is a tutorial on unix “job control”.

The following are part of bash, not separate utils, so there's no man page for them. They are documented in man bash. [see Linux: Bash Manual in Chapters, Using Emacs for Info]

cmd &Start a program in background. For example, ruby process_log.rb &
Ctrl+cStop the current program associated with your terminal. (sending SIGINT to it)
Ctrl+zSuspend the current program associated with your terminal. (sending SIGTSTP to it)
jobsList background processes
bg %numberRun the suspended command in background.
fg %numberResume a background process to foreground.
disown %numberSeparate a job ID number from jobs table.

unix process signal is a integer send to programs to tell it something. To see a list of all signals, type man kill.

Example of Using Job Control

Here's a common scenario of using job control:

  1. Start xlock with a second hand by xclock -update 1, it'll hog the terminal.
  2. Now, in terminal, press 【Ctrl+z】 to pause the program and returns you the prompt. (when the program is paused, it can't be used. You'll see that the second-hand stopped moving.)
  3. Type jobs to list all jobs and their ID in job table. Here's a sample output: [1]+ Stopped xclock -update 1
  4. Type bg %1 to start the process with job ID 1 in background.
  5. Now, it is as if you started xclock by xclock &.

the “xlock” example above can be any shell command.

Here's some other commands that are very useful. Note, many GUI apps these days will detach itself from terminal, even if you didn't start it with &.

setsid commandRun a program in a new session.
nohup commandRun a command immune to SIGHUP signal , and redirect stdout to a normal file.

Closing Terminal Kills My Program?


To run a server, you can do: nohup myserver > out.txt 2> err.txt < /dev/null &.

This will set stdout to out.txt, and stderr to err.txt, and stdin from /dev/null, and not receive signal SIGHUP signal, and remove this process from jobs table.

Linux Shell Basics

  1. Get System Info
  2. Shell Basics
  3. grep, cat, awk, uniq
  4. sort
  5. find, xargs
  6. diff Files/Dir
  7. dir size: du
  8. dir tree
  9. tar gzip bzip2 xz 7zip rar zip
  10. wget, curl, GET, HEAD
  11. rsync
  12. Install Packages

Sys Admin

  1. Job Control
  2. ps
  3. top
  4. htop
  5. RAM stat
  6. Users and Groups
  7. File Permission
  8. Opened Files: lsof
  9. shutdown, sleep


  1. Bash Keys, Terminal Keys, Man Page Keys
  2. Bash Prompt Setup
  3. Bash Color Prompt
  4. .bashrc, .profile, .bash_profile
  5. Virtual Console
  6. Terminal Control Sequence Keys
  7. Reset Terminal
  8. tmux
  9. man page
  10. Bash Manual in Chapters
  11. BASH Shell Misc Tips
  12. Log Terminal Session

Linux Desktop

  1. Most Useful GUI Apps
  2. Set Default App
  3. Shell Commands for GUI Apps
  4. Image Viewers
  5. Music Players
  6. Move File to Trash by Command
  7. X11 Selection and Clipboard
  8. How to Switch to LXDE, Xfce
  9. LXDE Keyboard Shortcuts
  10. LXDE/Openbox, Change Keyboard Shortcuts
  11. LXDE Set Key Repeat Rate
  12. LXDE/OpenBox, Disable Mouse Scroll Wheel Hide Window
  13. Xfce Keyboard Shortcuts
  14. Xfce Good Themes
  15. xmonad Keybinding
  16. How to Restart X11
  17. Why Tiling Window Manager Sucks
  18. Standard Fonts
  19. How to Install Font

If you have a question, put $5 at patreon and message me.