Bitpath

Lesson 2 · Unit 03

Signals and jobs

Ctrl-C, kill and kill -9, background jobs, and why TERM comes first

12 exercisesabout 3 min

What you practise

  • Ctrl-C and Ctrl-Z, kill (TERM vs KILL), &, jobs, fg, bg, nohup, why kill -9 is the last resort

Try a question from this lesson

Pick one

A script is stuck in an endless loop in your terminal. You press Ctrl-C and it stops. What did the terminal do?

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Signals

A signal is a small numbered message the kernel delivers to a process.

INT (2) is what Ctrl-C sends. TERM (15) is what kill sends by default: please exit. A program can catch either one, to clean up first or even to ignore it.

KILL (9) is different. The process never sees it: the kernel simply removes the process.

shell
kill 4242      # TERM: please exit
kill -9 4242   # KILL: no choice
kill -l        # list every signal

Concept

Jobs

The commands a shell has started are its jobs.

cmd & starts one in the background, so you get the prompt back. jobs lists them. fg brings one to the foreground.

Ctrl-Z pauses the foreground job, and bg lets a paused job carry on in the background.

$ sleep 300 &
[1] 4242
$ jobs
[1]+  Running    sleep 300 &
$ fg %1
sleep 300
^Z
[1]+  Stopped    sleep 300
$ bg %1
[1]+ sleep 300 &

9 more exercises in the app

  • 2× type the answer
  • 3× multiple choice
  • 1× true or false
  • 1× order the lines
  • 1× fill the blanks
  • 1× match the pairs

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy