Priority & Background Jobs
Nice Values (Priority)
When multiple processes want the CPU at once, the kernel's scheduler has to decide who goes first. Nice value is a hint you can give it, ranging from -20 (highest priority, most eager for CPU time) to +19 (lowest, most willing to step aside). The name comes from the idea that a high nice value makes a process "nicer" to everyone else competing for the CPU. Only root can set negative (higher-priority) values, so a regular user can't accidentally starve the whole system.
$ nice -n 10 ./batch.sh # start with lower priority
$ renice -n 5 -p 1234 # change a running process
Use nice to launch something at a lower priority from the start (a heavy batch job that shouldn't slow down interactive work), and renice to adjust the priority of something already running, by its PID.
Job Control
Every command you run at the shell is a job. Normally a job occupies your terminal until it finishes - job control lets you step away from it without killing it.
| Command | Action |
|---|---|
cmd & | Start in background |
Ctrl+Z | Suspend current job |
jobs | List shell jobs |
bg %1 | Resume job 1 in background |
fg %1 | Bring job 1 to foreground |
nohup cmd & | Survive logout |
disown | Detach from shell |
Ctrl+Z doesn't stop a job - it pauses it (sends SIGSTOP), freezing it in place so you get your prompt back; bg then resumes it in the background so it keeps running while you do something else, and fg brings it back to the foreground so it owns your terminal input again.
Warning: Closing your terminal (or losing an SSH connection) sendsSIGHUPto every job still attached to that session - by default this kills them, background or not. If you started a long build or server with a plain&and then log out, it dies with you.nohup cmd &runs the command in a way that specifically ignoresSIGHUP, so it survives your terminal closing;disownafter the fact detaches an already-running background job from the shell's job table so the shell no longer signals it on exit either.