[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: Re: Is it a bug of killall/pidof?
From: Denis Vlasenko <vda.linux () googlemail ! com>
Date: 2007-06-23 14:12:35
Message-ID: 200706231612.35459.vda.linux () googlemail ! com
[Download RAW message or body]
On Friday 22 June 2007 01:43, john bigZ wrote:
> I was wondering why my kill script didn't work. the reason I found
> that the 'killall' failed with 'no process killed', was 'killall'
> called 'pidof', 'pidof' didn't return a process id for the given
> process name. After through investigation of the busybox sourcecode,
> I found out, that pidof doesn't parse /proc/$PID/cmdline
> for the process name instead it cuts out the text between the round
> braces in /proc/$PID/stat. This text usually contains the name of argv[0]
> and somehow this text contains "exe" instead of the real process name
> itself. pidof/killall will then not be able to find the PID to the given
> process name (you may try "pidof exe" instead, if you don't believe me).
> I don't know how to fix this problem, can anyone help me or give me some
> hints? I'd appreciate your help!
This is complex. In Linux we have three ways to determine "process name":
1. /proc/PID/stat has "...(name)...", among other things. It's so-called "comm" field.
2. /proc/PID/cmdline's first NUL-terminated string. It's argv[0] from exec syscall.
3. /proc/PID/exe symlink. Points to the running executable file.
kernel threads:
comm: thread name
cmdline: empty
exe: <readlink fails>
executable
comm: first 15 chars of base name
(if executable is a symlink, then first 15 chars of symlink name are used)
cmdline: argv[0] from exec syscall
exe: points to executable (resolves symlink, unlike comm)
script (an executable with #!/path/to/interpreter):
comm: first 15 chars of base name (symlinks are not resolved)
cmdline: /path/to/interpreter (symlinks are not resolved)
exe: points to interpreter's executable (symlinks are resolved)
> and somehow this text contains "exe"
This is because you probably have FEATURE_PREFER_APPLETS=y (and maybe
FEATURE_SH_STANDALONE too), and therefore some commands started
from busybox shell, xargs or find are started by
execXXX("/proc/self/exe", applet_name, params....)
and therefore comm field contains "exe".
In busybox, pidof and killall are using find_pid_by_name, which is looking at
comm field only:
pid_t* find_pid_by_name(const char* procName)
{
pid_t* pidList;
int i = 0;
procps_status_t* p = NULL;
pidList = xmalloc(sizeof(*pidList));
while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_COMM))) {
if (strncmp(p->comm, procName, sizeof(p->comm)-1) == 0) {
pidList = xrealloc(pidList, sizeof(*pidList) * (i+2));
pidList[i++] = p->pid;
}
}
pidList[i] = 0;
return pidList;
}
Ok, I explained how it works, now: do we want it to be fixed? and how exactly?
--
vda
_______________________________________________
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic