views:

98

answers:

2

I'm running a script that performs a command that lasts too long, so I want to interrupt it. Any help? I've tried to search a lot, and I've been pointed to the kill command. Although, I can't get it to work. By the way, I'm using a Mac OS X. Thanks!

+1  A: 

Assuming you have the process' PID, send it a SIGINT signal:

kill -SIGINT PID

If you don't have the PID you can try pkill or killall, but they're somewhat less safe; a PID is the only way to uniquely identify a process. Right after you spawn the other process the PID should be in $!, so you can save it then

process-that-takes-a-long-time &
pid=$!
# other stuff
kill -SIGINT $pid
Michael Mrozek
What if I can't find the PID? Is there another way to replicate CTRL+C?
hassaanm
Be careful with `killall`. On some systems it's similar to `halt`.
Dennis Williamson
A: 

timeout 10 your_command

pixelbeat