[英]set a name to sleep process in shell
I'm a newbie to linux and has a task of writing a script to automate some work 我是linux的新手,其任务是编写脚本以使某些工作自动化
Currently I have a script (runme.csh) with content like this 目前,我有一个脚本(runme.csh),其内容如下
#!/bin/csh -f
read some settings from a file>
while (some condition)
< do some work >
sleep 600
end
Now I need to run copies of the script multiple times (copy the script to new file name and run) on same shell [tcsh] 现在,我需要在同一shell [tcsh]上多次运行脚本副本(将脚本复制到新文件名并运行)。
example 例
[aruna>] runme1.csh & [aruna>] runme1.csh和
[aruna>] runme2.csh & [aruna>] runme2.csh和
[aruna>] runme3.csh & [aruna>] runme3.csh和
Now if I wanted to kill one run I can do ps, find the PID of respective script by its name and kill. 现在,如果我想终止一次运行,则可以执行ps,通过其名称找到相应脚本的PID并终止。 However I have no way to find the pid of the sleep command that script executed.
但是,我无法找到脚本执行的sleep命令的pid。
Is there a way to give a name to the sleep process so that I can see which sleep process is executed by which script? 有没有一种方法可以给睡眠过程起个名字,以便我可以看到哪个睡眠过程由哪个脚本执行?
Thank you :) 谢谢 :)
It seems that you can't properly do that using bash
alone, as exec -a foo sleep 100
still shows up as sleep
when using ps
: 似乎单独使用
bash
无法正确执行此操作,因为使用ps
时exec -a foo sleep 100
仍显示为sleep
:
[~ ]$ ps -u corion
PID TTY TIME CMD
...
101468 pts/8 00:00:00 bash
101494 pts/8 00:00:00 sleep
But using Perl, you can easily change the name of the process because Perl supports assignment to $0
(the name of the process, in Perl): 但是,使用Perl,您可以轻松更改进程的名称,因为Perl支持分配给
$0
(进程的名称,在Perl中):
perl -wle '$0=shift;sleep shift' sleeper 100
[~ ]$ ps -u corion
PID TTY TIME CMD
...
100740 pts/8 00:00:00 bash
104067 pts/8 00:00:00 sleeper
The above oneliner changes the name to the first argument given and then sleeps as many seconds as the second argument given. 上面的oneliner将名称更改为给定的第一个参数,然后休眠与给定的第二个参数一样多的秒。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.