diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-23 14:56:43 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-23 14:56:43 +0000 |
commit | 198badafd82905c9a2e76eeacb7ce463d8518bda (patch) | |
tree | fcb367654b5c6cafdca09ef189342fc7019095fc /libbb/find_pid_by_name.c | |
parent | 118b81df76be0e372309d76196c8eedf19ac56cd (diff) | |
download | busybox-w32-198badafd82905c9a2e76eeacb7ce463d8518bda.tar.gz busybox-w32-198badafd82905c9a2e76eeacb7ce463d8518bda.tar.bz2 busybox-w32-198badafd82905c9a2e76eeacb7ce463d8518bda.zip |
pidof: size optimizations (-50 bytes)
Diffstat (limited to 'libbb/find_pid_by_name.c')
-rw-r--r-- | libbb/find_pid_by_name.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libbb/find_pid_by_name.c b/libbb/find_pid_by_name.c index e98616940..13ccb545d 100644 --- a/libbb/find_pid_by_name.c +++ b/libbb/find_pid_by_name.c | |||
@@ -9,6 +9,35 @@ | |||
9 | 9 | ||
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | 11 | ||
12 | /* | ||
13 | In Linux we have three ways to determine "process name": | ||
14 | 1. /proc/PID/stat has "...(name)...", among other things. It's so-called "comm" field. | ||
15 | 2. /proc/PID/cmdline's first NUL-terminated string. It's argv[0] from exec syscall. | ||
16 | 3. /proc/PID/exe symlink. Points to the running executable file. | ||
17 | |||
18 | kernel threads: | ||
19 | comm: thread name | ||
20 | cmdline: empty | ||
21 | exe: <readlink fails> | ||
22 | |||
23 | executable | ||
24 | comm: first 15 chars of base name | ||
25 | (if executable is a symlink, then first 15 chars of symlink name are used) | ||
26 | cmdline: argv[0] from exec syscall | ||
27 | exe: points to executable (resolves symlink, unlike comm) | ||
28 | |||
29 | script (an executable with #!/path/to/interpreter): | ||
30 | comm: first 15 chars of script's base name (symlinks are not resolved) | ||
31 | cmdline: /path/to/interpreter (symlinks are not resolved) | ||
32 | (script name is in argv[1], args are pushed into argv[2] etc) | ||
33 | exe: points to interpreter's executable (symlinks are resolved) | ||
34 | |||
35 | If FEATURE_PREFER_APPLETS=y (and more so if FEATURE_SH_STANDALONE=y), | ||
36 | some commands started from busybox shell, xargs or find are started by | ||
37 | execXXX("/proc/self/exe", applet_name, params....) | ||
38 | and therefore comm field contains "exe". | ||
39 | */ | ||
40 | |||
12 | /* find_pid_by_name() | 41 | /* find_pid_by_name() |
13 | * | 42 | * |
14 | * Modified by Vladimir Oleynik for use with libbb/procps.c | 43 | * Modified by Vladimir Oleynik for use with libbb/procps.c |