0

I want to sent a SIGNAL to a process after .5 seconds.

Maybe this is not a good idea to do but I want to do it for an uncommon temporary case.

I tried like following, but its not working.

(sleep .5;kill -9)| some_process

2 Answers 2

5

Signals aren't directed to pipes; they're directed to process identifiers (pids). I might try something like this:

some_process & sleep .5; kill -KILL $!

which would run some_process in the background (that's what the & is for). After half a second, it will used the variable $! which indicates the pid of the last backgrounded process.

(Although sleep on some systems only accepts an integer.)

Sign up to request clarification or add additional context in comments.

Comments

1

sleep .5; kill -9 $(pidof some_process) should work. pidof returns a process id for a process name. The $() returns the result of the command to the kill command. An alternative would be:

sleep .5; pidof some_process | xargs kill -9

check man pidof for details.

Edit: there is also timeout. timeout -s SIGKILL 0.5s some_process should do the trick if I understood your question correctly.

4 Comments

No. I want to kill the process which is after this PIPE. This some_process is not a different process.
Basically, I will not get the pid of some_process. So need to sent SIGNAL through pipe to some_process
So the process should start and should be killed after 0.5 seconds? Maybe man timeout helps here? timeout -k e.g.?
why can't you get the pid? Could you clarify the problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.