问个 linux 的小问题:
不知道 pidof 是根据什么来查找进程号的,pidof g_queue 获取不到
通过下面的命令,可以根据 command 来过滤出为想要的进程
ps -eo pid,command|grep g_queue 可以找到所有 g_queue 的进程号
然后怎么实现 kill -9 pidof xx
的效果呢?在这个命令上如何获取 id 的数组?
# ps -eo pid,command|grep g_queue
28897 /usr/local/bin/ruby /usr/local/bin/rake g_queue:worker workers=UploadQueue RAILS_ENV=production
28902 /usr/local/bin/ruby /usr/local/bin/rake g_queue:worker workers=UploadQueue RAILS_ENV=production
28905 /usr/local/bin/ruby /usr/local/bin/rake g_queue:worker workers=UploadQueue RAILS_ENV=production
28909 /usr/local/bin/ruby /usr/local/bin/rake g_queue:worker workers=UploadQueue RAILS_ENV=production
28913 /usr/local/bin/ruby /usr/local/bin/rake g_queue:worker workers=UploadQueue RAILS_ENV=production
28917 /usr/local/bin/ruby /usr/local/bin/rake g_queue:worker workers=UploadQueue RAILS_ENV=production
28920 /usr/local/bin/ruby /usr/local/bin/rake g_queue:worker workers=UploadQueue RAILS_ENV=production
29461 grep g_queue
解决方法:
#!/bin/bash
ps -eo pid,rsz,command|grep g_queue|grep -v grep
while read a1 a2 a3
do
kill -9 $a1
done
下面这样写,怎么也启动不起来
#!/bin/bash
for i in {1..4}
do
rake g_queue:worker workers=XxQueue RAILS_ENV=production &
done
whereis rake /usr/local/bin/rake 下面这样写,怎么也启动不起来
#!/bin/bash
for i in {1..4}
do
#这里指定rake的安装路径,即可以解决
/usr/local/bin/rake g_queue:worker workers=XxQueue RAILS_ENV=production &
done
使用定时任务 crontab -e 编辑如下内容:
*/10 * * * * /bin/bash /usr/localstart.sh #每10分钟运行一次
*/20 * * * * /bin/bash /usr/local/kill.sh #每20分钟运行一次