Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.3: Kill another user logged in under Fast User Switching' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: Kill another user logged in under Fast User Switching
Authored by: thrig on Dec 01, '03 12:09:38PM
% sudo kill -9 1234

No! Bad admin! Never use the KILL signal to kill by default. This is process assassination, and should never be done. Process 1234 might be the parent for any number of child processes that will end up in limbo because the KILL signal does not give the parent a chance to inform any children. Additionally, the KILL signal prevents a process from cleaning up any temporary files and shared memory segments, or shutting down socket connections. Instead, use the TERM signal by default, and work up to a KILL if the process in question proves resilient.



[ Reply to This | # ]
10.3: Kill another user logged in under Fast User Switching
Authored by: Clint MacDonald on Dec 01, '03 04:36:54PM
Never use the KILL signal to kill by default. [...] Instead, use the TERM signal by default, and work up to a KILL if the process in question proves resilient.

Could you explain more about this, please? I am a command line newbie, and am unfamiliar with TERM. To be honest, I would prefer another way to logout another user as Admin, since kill has so many problems (as you point out).



[ Reply to This | # ]
10.3: Kill another user logged in under Fast User Switching
Authored by: 47ronin on Dec 01, '03 06:18:54PM

Yeah, you should NEVER use kill -9 unless you have to.. It's a last resort. the -9 flag forces the computer to kill the process without prejudice, and without cleaning up after itself. The TERM flag will attempt to close out any remainding resources that the process was using before trying to cleanly exit it.

Think of TERM as "Come out with your hands behind your head!"

Think of -9 as "Shoot the bastard where he stands!"



[ Reply to This | # ]
10.3: Kill another user logged in under Fast User Switching
Authored by: hamarkus on Dec 02, '03 10:00:59AM

I can only confirm this, I have managed to create kernel panics and stuck sub-processes (requiring a restart) with kill -9.

One thing one should always try before reverting to kill -9, is to apply the kill command several times. Killing e.g. pppd usually takes 4 to 5 kill attempts before it terminates.



[ Reply to This | # ]
10.3: Kill another user logged in under Fast User Switching
Authored by: mikeygstl on Dec 02, '03 11:11:58AM

kill -15 `ps --sort -pid axo%p.%u | grep <USERNAME> | cut -d. -f1 -`

That should do it nicely. Sends SIGINT - not sigterm or sigkill.



[ Reply to This | # ]
10.3: Kill another user logged in under Fast User Switching
Authored by: mikeygstl on Dec 02, '03 11:13:26AM

kill -15 `ps --sort -pid axo%p.%u | grep <USERNAME> | cut -d. -f1 -`

That should do it nicely. Sends SIGINT - not sigterm or sigkill.



[ Reply to This | # ]
10.3: Kill another user logged in under Fast User Switching
Authored by: grumpy on Dec 01, '03 08:54:08PM

Using the TERM signal is no different to using the KILL signal if the application hasn't registered a special signal handler for the TERM signal to gracefully shutdown the process. Check out the sigaction manual page and you will see this is the case as the default action for TERM is "terminate the process", exactly the same as KILL.

Thus you are at the mercy of the application developer as to whether they intercept TERM and do anything special. You often see programs from the UNIX world which simply don't bother because the developers don't know any better. A decent program will catch both TERM and INT and shutdown nicely if they need to.



[ Reply to This | # ]