From: 7stud -- Date: 2007-10-29T16:42:31+09:00 Subject: Re: Kill an IO.popen'ed program? Jared Davis wrote: > Hi, > > I'm looking for a way to forcibly terminate a process started with a > pipe. That is, when I run: > > file = IO.popen("sleep 300", "r+") > file.close > > The file.close command just hangs and waits for the sleep command to > finish. Is there some way I can instead say, "I don't care if it's > finished or not, kill the program now and close the pipe"? > > Thanks, > Jared Try this: p = IO.popen("sleep 10", "r+") id = p.pid puts id sleep(5) Process.kill("SIGALRM", id) The man page for sleep says: ----- The sleep utility exits with one of the following values: 0 On successful completion, or if the signal SIGALRM was received. >0 An error occurred. ----- Or you can issue a shell command using system(): #Process.kill("SIGALRM", id) system("kill -SIGALRM #{id}") -- Posted via http://www.ruby-forum.com/.