Linux: Job Control
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
[see Linux: Bash Manual in Chapters, Using Emacs for Info]
|Start a program in background. For example, |
|【Ctrl+c】||Stop the current program associated with your terminal. (sending SIGINT to it)|
|【Ctrl+z】||Suspend the current program associated with your terminal. (sending SIGTSTP to it)|
|List background processes|
|Run the suspended command in background.|
|Resume a background process to foreground.|
|Separate 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
Example of Using Job Control
Here's a common scenario of using job control:
- Start xlock with a second hand by
xclock -update 1, it'll hog the terminal.
- 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.)
jobsto list all jobs and their ID in job table. Here's a sample output:
+ Stopped xclock -update 1
bg %1to start the process with job ID 1 in background.
- Now, it is as if you started xclock by
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
|Run a program in a new session.|
|Run a command immune to SIGHUP signal , and redirect stdout to a normal file.|
Closing Terminal Kills My Program?
- Don't close your terminal by clicking the window close. Close it by 【Ctrl+d】. Because, when you click on close, it may kill all programs you launched from it.
- if you do
emacs &, then close your GUI terminal (by clicking on the close button), it'll also take down your emacs.
- You can use
setsid emacsto launch program. It runs the program in its own session.
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
- Get System Info
- Shell Basics
- grep, cat, awk, uniq
- find, xargs
- diff Files/Dir
- dir size: du
- dir tree
- tar gzip bzip2 xz 7zip rar zip
- wget, curl, GET, HEAD
- Install Packages
- Job Control
- RAM stat
- Users and Groups
- File Permission
- Opened Files: lsof
- shutdown, sleep
- Bash Keys, Terminal Keys, Man Page Keys
- Bash Prompt Setup
- Bash Color Prompt
- .bashrc, .profile, .bash_profile
- Virtual Console
- Terminal Control Sequence Keys
- Reset Terminal
- man page
- Bash Manual in Chapters
- BASH Shell Misc Tips
- Log Terminal Session
- Most Useful GUI Apps
- Set Default App
- Shell Commands for GUI Apps
- Image Viewers
- Music Players
- Move File to Trash by Command
- X11 Selection and Clipboard
- How to Switch to LXDE, Xfce
- LXDE Keyboard Shortcuts
- LXDE/Openbox, Change Keyboard Shortcuts
- LXDE Set Key Repeat Rate
- LXDE/OpenBox, Disable Mouse Scroll Wheel Hide Window
- Xfce Keyboard Shortcuts
- Xfce Good Themes
- xmonad Keybinding
- How to Restart X11
- Why Tiling Window Manager Sucks
- Standard Fonts
- How to Install Font
If you have a question, put $5 at patreon and message me.