First, demand:
A process with a process name that may correspond to multiple process numbers is monitored on Linux, and output to a log file if there are multiple.
The above problem is for a timed program has not run the end, to the next moment the program is running again, to avoid causing repeated calls interface error.
Second, the settlement:
#!/Bin/sh# (Sh pid_monitor.sh)&#被监控的进程放在后台运行 whiletrue #死循环不断监控后台运行的进程do pid_num=' PS-Ef|Grep-V grep|grep root_sub_i2_data|Awk'{print $}'|Wc-l ' #取后台运行程序的进程号数量if [$pid _num-gt 1]; #判断被监控的进程数是否大于1, note the semicolon, the shell and Python are different ThenEcho'to monitor multiple exception processes:' >>Pid_monitor.LogPS-Ef|Grep-V grep|grep root_sub_i2_data|Awk'{print $2,$5}' >>Pid_monitor.Log#打印进程号和启动时间Elseecho ' Date ''only monitor the number of 1 processes, normal ...' >>Pid_monitor.LogSleep -#休息30秒 Fidone
Third, reference
Http://blog.chinaunix.net/uid-30106268-id-5030040.html
Http://www.jb51.net/article/34332.htm
Linux process multi-process number real-time monitoring