开发者

Why can't I use killall with the new name given to a child process with execvp() on Linux?

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开发者_JS百科 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


try using pkill instead of killall


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜