CHAPTER 8 · 6 lessons · 78 exercises
Processes and signals
See what is running right now. Stop something that will not stop. Run things in the background.
The command you typed does not come back. This is the chapter about what to do then.
Each running program is called a process, and each one has a number (a PID). ps lists them.
ps— the list of what is running;-opicks the columnspstree— see the parent and child relations as a treetop— watch, as it moves, what is eating the CPU and the memorykill— send a signal to a process&jobsfg— run something behind you, and call it backnice— run it with a lower priority
The name kill overdoes the threat a little; the tool really only sends a signal. The default signal (TERM) is a request to "tidy up and finish", and for something that will not listen you send -9 (KILL). Knowing that difference is how you stop things without breaking your data.
You have used Ctrl-C already. That too is sending a signal (INT). This chapter is where what was going on behind the button becomes clear.
Look at the family relations too. Every process branches off init (number 1), and your shell is one of those branches.
Lessons in this chapter
See what is running
- 39See what is running (`ps`)Processes and PIDs. List them with ps, and pick the columns you want with -o.Go to the exercises
- 40See the parentage as a tree (`pstree`)Every process branches off from 1. See the shape of it at a glance.Go to the exercises
- 41Who is heavy right now (`top`)ps is a photograph, top is a film. Find what is eating the CPU and the memory.Go to the exercises
Send a signal, run in the background
- 42Send a signal and stop it (`kill`)kill is not a tool for killing but for sending a signal. TERM the request, and KILL the last resort.Go to the exercises
- 43Run it in the background (`&` and `jobs`)The way out when nothing comes back. Send it behind you, and call it back.Go to the exercises
- 44Give up your place in the queue (`nice`)Let work that is in no hurry stand back, so what you want now feels lighter.Go to the exercises