tags:

views:

40

answers:

1

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.

+2  A: 

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.

Roman Cheplyaka