هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
The quick answer
Step by step
- Find the exact process. Check the full command line, the user and the start time — do not kill the wrong one:
pgrep -a -f 'java.*shop-api'
ps -o pid,ppid,user,stat,etime,cmd -p 4311
PID PPID USER STAT ELAPSED CMD
4311 1 app S 02:13:08 /bin/bash /usr/local/bin/backup.sh- Is it a service or a container? Then stop it the managed way — otherwise systemd or Docker starts it again at once:
systemctl status 4311
systemctl restart shop-api
systemctl kill --signal=SIGKILL shop-api
docker stop -t 30 web
docker kill web- Send the right signal:
| Signal | Number | Use |
|---|---|---|
SIGTERM | 15 | Default of kill: stop cleanly. Always try this first. |
SIGINT | 2 | Like Ctrl+C. |
SIGHUP | 1 | Many daemons reload their config (nginx, sshd, rsyslog). |
SIGKILL | 9 | The kernel stops it at once. No clean-up, temp files stay, data can be lost. |
SIGSTOP / SIGCONT | 19 / 18 | Pause and continue (good for "what is this doing?"). |
- Kill by name or by port (careful — it can match more than you think; test with
pgrepfirst):
pgrep -l -u alice python
pkill -u alice -f 'python report.py'
fuser -v 8080/tcp
fuser -k -TERM 8080/tcp- Kill a whole tree (a script that started children): kill the process group, or let systemd do it for a service:
The minus before the number means "the process group 4311".
- Stop it from running too long next time:
timeout 30m /usr/local/bin/backup.sh
timeout -k 10s 5m ./job.shCheck that it worked
No line for the PID and the port is free. For a service: systemctl status shop-api shows active (running) with a new PID after the restart.
Common problems
| Problem | Cause | Fix |
|---|---|---|
kill -9 does nothing, state D in ps | The process waits for the kernel (disk, NFS). It can not be killed until the I/O ends. | Fix the storage/NFS problem; sometimes only a reboot helps. |
Process shows <defunct> (state Z) | A zombie: already dead, the parent did not collect it. | It uses no CPU/RAM. Restart or kill the parent (ps -o ppid= -p PID). |
| It comes back right after kill | systemd (Restart=), Docker (--restart), or Kubernetes restarts it. | Stop the service / container / scale the deployment instead. |
Operation not permitted | It belongs to another user. | Use sudo, after you checked it is the right process. |
pkill killed too much | The pattern matched other commands too. | Always run pgrep -a -f PATTERN first; use exact patterns or -x. |
| Port still busy after the kill | A child process holds it, or the socket is in TIME_WAIT. | ss -ltnp / fuser -v PORT/tcp; TIME_WAIT ends by itself. |
Go further
- Command pages: kill, pkill, killall, ps, fuser, systemctl.
- Next how-tos: Check memory and CPU usage, Find which process uses a port, Start, stop and restart a service.
- Learn it: RH124 — Signals, RHCSA — Signals, RHCSA — Zombies, TLCL — Signals.
- Practise: Lab: control jobs, priorities and signals.
1Why should you try kill PID before kill -9 PID?
SIGTERM lets the program close files and connections cleanly; SIGKILL stops it at once and can lose data.
2A process is in state D and kill -9 does not work. Why?
It waits for I/O inside the kernel (often disk or NFS); it can only end when that I/O ends.