I'm trying to execute a command for an x amount of seconds and then stop it afterwards. I guess normally you'd do this with the timeout
command, but this program does not seem to be available on my machine, so I'm trying to still get this to work a different way.
Here's one of the commands I've tried:
./some_program & sleep 5; kill `pidof some_program`
Normally when I manually interrupt some_program
using ctrl+c, it generates a csv file of the results, but the above command just seems to stop it, and there is no csv file that is created. If I use kill -9
, it will terminate the program, but again, no csv file will be generated.
How can I automatically stop the program after an x number of seconds and still cause it to generate the csv file? (I've tried kill -2
, kill -3
andkill -15
.)