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.

link|improve this question
A bit off topic here, but how do you find the PID of time? It doesn't show up with ps aux | grep time or in htop/top (running in another terminal) – Azz Oct 28 '10 at 8:05
feedback

2 Answers

up vote 1 down vote accepted

most unixes have pkill, which kills a process based on name Try: pkill my_program

/usr/bin/time my_program sleep 5 pkill -TERM my_program

Also, don't kill with -9. It doesn't allow cleanup.

link|improve this answer
feedback

I've never dabbled in unix but can't you just kill "my_program" instead of "time"? I would expect it to have it's own process id.

link|improve this answer
Yep, while I've been looking for time's PID, I found killing the process time is timing works a treat, and then time finishes up with it's summary information. – Azz Oct 28 '10 at 8:13
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.