开发者

Starting and stopping a process daily using the shell?

I know I can start the process with cron, but how would I go about stopping it? I thought about starting a new process1 everyday at 00:00, then at 23:59 I'd start a process2 doing ps -aux | grep process1, getting the pid from the line and then 开发者_如何学JAVAkilling it, but I was wondering if there's be a better way to do it.

I could use Python or Java too if it's easier with either language.


Record its PID:

nohup my_service &
echo $! > /var/run/my_service.pid

and then kill by that PID.

You might want to check both PID and process name to make sure that during the day the process did not crash and some other process did not get that PID. (And even better idea would be to set up supervisor.) But if you are sure that there are no other process with that name you can simply use pkill or killall.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜