1
votes

Assume I have an executable called 'exe' which spawns a child process. This child process needs to become a daemon and we need to change its name. Next I want to use killall to send a signal to this process using the new name, but I need to use the old name.

The order of events is as follows:

  1. start 'exec'
  2. fork -> exit if parent
  3. detach (chdir, setsid, umask)
  4. execvp('exec', 'daemon', ...)

On 4, argv[0] is set to 'daemon'.

After this, I can do a 'ps' and a 'top' and I neatly see the name 'daemon' appearing in the output of these commands. However, when I try to kill the process (send a signal to it) using killall, I have to provide the name 'exec' and not 'daemon'.

It seems as if the kernel is not fully aware of the new name.

The reason why I need this functionality is that I want to spawn a few child process with different responsibilities using the same executable. I also want to to be able to stop and start them individually by referring to them by name. And I don't want to symlink the new names to the common exec executable (like busybox does).

Is there a way around this?

I'm using Linux Ubuntu 9.10.

Cheers, Johan

2
Why don't you just retain all your child pid's and use those to interact with them?Ramon
Seems like remembering the pid's is going to be a lot safer than doing "killall" and potentially targeting other (non-child) processes with the same name.David Gelhar
The idea is to be able to have some interaction on the shell with the running processes. using 'killall' seemed the most obvious without resorting to DIY tools that need to get the pid from somewhere...Johan

2 Answers

2
votes

try using pkill instead of killall

2
votes

Some tools use the binary name, others use the process name (what you pass as execvp first argument). Try to cope with it :)