Is it a bug of killall/pidof?
john bigZ
john.bigz at yahoo.com
Thu Jun 21 23:43:39 UTC 2007
Hi,
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!
Regards,
John
------------------------------------------------------------------
the experiment I did listed below, (first I tried to kill all the processes named 'syslogd', it failed. Then I tried to kill all the httpd processes, it worked as /proc/$PID/stat contained the right process name).
firewall# ps -ef
PID Uid VmSize Stat Command
1 root 288 S init
2 root SW [keventd]
3 root SWN [ksoftirqd_CPU0]
4 root SW [kswapd]
5 root SW [bdflush]
6 root SW [kupdated]
7 root SW [khubd]
645 root 280 S syslogd -m 0 -C
646 root 264 S klogd
850 root 280 S syslogd -m 0 -C
856 root 264 S klogd -c 1
892 root 304 S /usr/sbin/sshd -p 22
905 root 3588 S /usr/local/sbin/httpd -f /etc/httpd.conf
922 root 292 S crond -L /dev/null
926 root 272 S /sbin/getty 38400 tty1
927 root 272 S /sbin/getty 38400 tty2
928 root 272 S /sbin/getty 38400 tty3
929 root 5092 S /usr/local/sbin/httpd -f /etc/httpd.conf
946 root 5048 S /usr/local/sbin/httpd -f /etc/httpd.conf
977 root 428 R /usr/sbin/sshd -p 22
978 root 332 S -sh
1031 root 252 R ps -ef
firewall# killall -9 syslogd
killall: syslogd: no process killed
firewall#
firewall# cat /proc/850/stat
850 (exe) S 1 849 849 0 -1 64 12 0 15 0 0 4 0 0 9 0 0 0 980 1077248 70 4294967295 134512640 134770336 3221225008 3221224576 1074021311 0 0 69633 24582 3222503337 0 0 17 0
firewall# cat /proc/946/stat
946 (httpd) S 905 905 905 0 -1 320 552 438 108 1565 16 18 0 12 9 0 0 0 26755 621
3632 1262 4294967295 134512640 136027432 3221224992 3221224364 1074081392 0 0 40
96 71329387 3223297762 0 0 17 0
firewall# killall -9 httpd
firewall# ps -ef
PID Uid VmSize Stat Command
1 root 288 S init
2 root SW [keventd]
3 root SWN [ksoftirqd_CPU0]
4 root SW [kswapd]
5 root SW [bdflush]
6 root SW [kupdated]
7 root SW [khubd]
645 root 284 S syslogd -m 0 -C
646 root 264 S klogd
850 root 280 S syslogd -m 0 -C
856 root 264 S klogd -c 1
892 root 304 S /usr/sbin/sshd -p 22
922 root 292 S crond -L /dev/null
926 root 272 S /sbin/getty 38400 tty1
927 root 272 S /sbin/getty 38400 tty2
928 root 272 S /sbin/getty 38400 tty3
977 root 428 R /usr/sbin/sshd -p 22
978 root 332 S -sh
1039 root 252 R ps -ef
firewall#
syslogd-m0-Cfirewall# busybox
BusyBox v1.2.1 (2007.04.23-19:37+0000) multi-call binary
Usage: busybox [function] [arguments]...
or: [function] [arguments]...
BusyBox is a multi-call binary that combines many common Unix
utilities into a single executable. Most people will create a
link to busybox for each function they wish to use and BusyBox
will act like whatever it was invoked as!
Currently defined functions:
[, [[, arping, ash, basename, busybox, cat, chmod, chown, clear, cp, crond, crontab, cut, date, dd, df, dirname,
dmesg, dos2unix, du, echo, false, fgrep, find, free, getopt, getty, grep, gunzip, gzip, halt, head, hostname,
hwclock, id, ifconfig, init, insmod, ipcalc, kill, killall, klogd, ln, logger, login, logread, ls, lsmod, makedevs,
md5sum, mesg, mkdir, mknod, more, mount, mv, nameif, nc, nslookup, passwd, pidof, ping, poweroff, printf, ps,
pwd, rdate, reboot, reset, rm, rmdir, route, sed, sh, sleep, sort, stty, sync, syslogd, tail, tar, test, time,
touch, tr, traceroute, true, tty, udhcpc, umount, uname, uniq, unix2dos, uptime, watchdog, wc, wget, which,
yes, zcat
firewall#
---------------------------------
Expecting? Get great news right away with email Auto-Check.
Try the Yahoo! Mail Beta.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.busybox.net/pipermail/busybox/attachments/20070621/c7206b17/attachment-0002.htm
More information about the busybox
mailing list