LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   killall doesn't work depending on how it's called (https://www.linuxquestions.org/questions/linux-newbie-8/killall-doesnt-work-depending-on-how-its-called-892779/)

jeriryan 07-20-2011 01:59 PM

killall doesn't work depending on how it's called
 
I've got a daemon that, when started manually from the command line as root, will eventually (after triggered) call killall5 and kill all running processes. But when the daemon is started as an init script in /etc/init.d, the killall5 doesn't actually kill anything when it is eventually triggered. I know the daemon runs, but the killall5 doesn't kill any processes. I know that killall5 excludes processes in it's own session, but as I noob I don't really understand how that helps me.

Looking at ps -ef for my daemon, when started thru the init scripts it looks like this:
root 5408 1 3 18:23 ? daemon_name
and of course PID 1 is init [3].

when started manually, the trace of the process which eventually leads back to init [3] is much longer. Parent PID of the daemon is -bash, parent of that is su -, parent of that is bash, parent of that is, sshd (I'm sshd in), ..., eventually back to init [3].

So what does the "except kernel threads and the processes in its own session" clarifier in killall5 mean and is it preventing me from killing processes when the daemon calls it when the daemon is started in /etc/init.d?

MacKtheHacK 07-20-2011 03:23 PM

A "session" is the set of processes descended from a login process, or some other process that called setsid(2). Each process is a member of a "process group" (or "session"), which is used to indicate that processes are logically related in some way. A daemon process should call setsid(2) to place itself into a new process group and disassociate itself from any controlling terminal (along with closing its standard I/O streams and such stuff).

Killall5 does not kill processes in its own process group to avoid killing the shell you invoked it from. If it didn't skip over it's process group, you would get logged off whenever you ran it. Or the rc-script that runs it would get killed off and wouldn't be able to continue the shutdown process.

Kernel threads are the process-table entries whose command names are shown in square brackets. You don't want killall5 to stop them or the kernel would stop right away.

I'm not sure why it isn't killing anything when it is run as a daemon, when it is presumably the only process in its process group. It should kill off every other process. So without more data, I'm at a loss here. But hopefully the above info will help you.

Try checking the exit status of killall5 to see if it tried to kill anything or not.


All times are GMT -5. The time now is 11:46 AM.