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.

CommandAction
cmd &Start in background
Ctrl+ZSuspend current job
jobsList shell jobs
bg %1Resume job 1 in background
fg %1Bring job 1 to foreground
nohup cmd &Survive logout
disownDetach 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) sends SIGHUP to 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 ignores SIGHUP, so it survives your terminal closing; disown after the fact detaches an already-running background job from the shell's job table so the shell no longer signals it on exit either.