System Administration
Showing results for 
Search instead for 
Did you mean: 

User unable to kill self process

Regular Advisor

User unable to kill self process

I know the /proc store the user login process , but I found that some user can't kill their SELF process in /proc , the file permission is dr-xr-xr-x , I am strange that some user can but some user can't , can advise what is wrong in my system ? can advise how can I make sure they can kill all their SELF process ? thx.
James R. Ferguson
Acclaimed Contributor

Re: User unable to kill self process


You need to define the signal sent. Some signals can be trapped (caught) and ignored. For example, if you want a shell script to be immune to the user typing CTRL_C (which is a 'kill -INT') you would write:

trap 'echo I refuse to do that!' INT
while true
echo "Enter anything..."
read LINE
echo "You entered '${LINE}'"

Now, if you run this script you cannot stop it by either typing CTRL_C on the keyboard or by sending:

# kill -INT

A simple 'kill ' command is the same as saying:

# kill -TERM

This is another signal that can be trapped and ignored.

Some signals cannot be caught or ignored. A 'kill -9' (kill -KILL ) is one of them. Using this brutal kill should be a choice of last restort, however. If used, the program receiving this signal cannot 'trap' it and perform any cleanup of temporary files or shared memory before it exits. This can be deleterous to your server in the long run.


Honored Contributor

Re: User unable to kill self process

Your user might have misunderstood what /proc/self is.

Each process sees /proc/self as pointing to itself. If process 12345 examines /proc/self, it sees it pointing to /proc/12345; if process 4321 simultaneously examines /proc/self, for that process it points to /proc/4321. In /proc this is possible, because /proc is a virtual filesystem: all data in it is generated _at the time it's requested_.

When your user is viewing the directory listing of /proc, he/she usually sees the /proc/self as pointing to the process that lists the contents of the directory. If this process was started from the command line (i.e. the "ls" command), that process ends after producing the listing, so the information gained by examining /proc/self is already obsolete!

If your user tries to do something like:

kill $(cat /proc/self/stat | cut -d " " -f 1)

the expected result is something like:

bash: kill: (24482) - No such process

because the process number (here 24482) refers to the process that executed the "cat /proc/self/stat" command, which has already died when the kill command starts executing.

If your user is writing a script and wants the script to stop itself, the simplest way would be to use the command "exit". If the script needs to send some signal to itself for some reason, the variable $$ contains the process ID of the shell that's running the script. It's available in all POSIX-compliant shells, including bash.

The file permissions of /proc/self will not determine whether the user can kill a process or not. If a process is running with the same userid as the user, the user owns the process and can kill it.