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 killing 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.

Answers


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.


Need Your Help

Treeview not showing my children

c# wpf xaml treeview

I've not used the TreeView before other than in a few tutorials to get the hang of them. I thought I had, it turns out I haven't.

Is there easy way to install SSH in xampp for windows?

windows ssh xampp

Is there easy way to install SSH in xampp for windows ?