Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|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
add comment

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.

share|improve this answer
add comment

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.

share|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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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