tags:

views:

30

answers:

2

I want to check how long time my program takes. Then I using "/usr/bin/time my_program". When it takes more than 5 seconds, I want to kill it. I tried "kill -9 TIME_S_PID", time is killed, but my_program is still running. So how to kill my_program?

Sorry, my English is really bad...

Thanks.

A: 

As @Soulseekah said, killall my_program works.

Xhacker Liu
A: 

Note that killall, as its name suggests, will kill all instances of your program. A better way would be to make a wrapper script:

#!/bin/sh
echo "$$" # print the PID of the current process
exec my_program

Then you execute /usr/bin/time my_wrapper_script, which prints PID of this instance of your program, and kill it when you want with kill -9 "$my_prog_pid".

Roman Cheplyaka