Linux version: CentOS 7
[weizhong@bja /tmp]
$ll apis_response_time_analysis.pid
-rw-r--r-- 1 weizhong users 5 Jan 22 09:40 apis_response_time_analysis.pid
[weizhong@bja /tmp]
$cat apis_response_time_analysis.pid
20795
[weizhong@bja /tmp]
$sudo ps -ef | grep 20795
weizhon+ 24876 9196 0 11:41 pts/2 00:00:00 grep --color=auto 20795
I can't find the PID, then I've tried to kill it by my account.
However, it saied Operation not permitted instead of No such process
[weizhong@bja /tmp]
$kill -9 20795
-bash: kill: (20795) - Operation not permitted
[weizhong@bja /tmp]
$kill -9 20795123 <--- a pid not exists
-bash: kill: (20795123) - No such process
then I tried to kill it with sudo
, I've executed
[weizhong@bja /tmp]
$sudo kill 20795 <-- no output
[weizhong@bja /tmp]
$sudo kill -9 20795
kill: sending signal to 20795 failed: No such process
Then I executed by my account again
[weizhong@bja /tmp]
$kill 20795
-bash: kill: (20795) - No such process
I'm sure that pid 20795 is generated by my account. Currently I can't find 20795, but when I kill it, return Operation not permitted
instead of No such process
, I wanna know why, and why my process need to be killed by sudo
Best Answer
You are not the owner of the process you are trying to kill. This is the reason for both
ps
output — which did not list process 20795 (see @kamil-maciorowski answer) — and thesudo
requirement to kill 20795.You can use
ps aux
to list all processes including those you don't own. You can also use-p
argument to show a specific process which best fit your need:You will see something like this:
My guess is that user will be root (elevated privileges) or maybe another specific system user. You then need
sudo
to kill a process you don't own. And you succeed to kill it. The empty answer forsudo kill 20795
tells it worked.