The program is still on the machine
The window closed and the computer is still slow. The program did not leave. On Linux, every running program is a process, and it keeps the machine busy until it is stopped.
Closing the window does not always stop the process. Its number stays on the list.
The number in the PID column
ps aux lists what is running. The PID column is that process's number. The program name sits at the end of the line. That name confirms the number belongs to the stuck program.
aluno@desafio:~$ ps aux
USER PID %CPU COMMAND
aluno 4821 98.2 python app.py
aluno 2204 0.1 bashpython app.py is 4821 and it is using almost the whole processor. bash is the terminal itself, at 2204. The number you want is the stuck program's number.
Solve
In the listing, python app.py is the heavy one. Which number do you use to talk about it?
Ask it to stop
kill 4821 asks that process to leave. The request gives it time to close a file and let go of what it had open. The terminal writes nothing when it accepts the request.
Then you run ps aux again. If the 4821 line is gone, the program left.
aluno@desafio:~$ kill 4821
aluno@desafio:~$ ps aux
USER PID %CPU COMMAND
aluno 2204 0.1 bashSolve
You ran kill 4821 and the line disappeared from ps. What happened?
-9 comes last
If ps still shows the same 4821, the process ignored the request. Then kill -9 4821 comes in. This request forces it out immediately. The process cannot save what it had open.
That is why -9 waits for the first try. kill without the extra number already works when the program can still say goodbye.
aluno@desafio:~$ ps aux
USER PID %CPU COMMAND
aluno 4821 98.2 python app.py
aluno@desafio:~$ kill -9 4821Figure it out
kill 4821 was already sent and ps still shows 4821. What is the next command?
The number that is already gone
The process can leave on its own between one command and the next. Then kill answers No such process. The number is no longer on the list.
aluno@desafio:~$ kill 4821
bash: kill: (4821) - No such processThis notice is about the number. The process is already gone. If the answer is Operation not permitted, the process belongs to another user. Who can act on each thing is the subject of permissions.
Figure it out
The terminal wrote No such process. What does that say?
Categories