Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send signal to process from command line

Tags:

linux

signals

I read about signals and I know how to send a signal to a process from the command line. Just do

ps -C executable

to know the pid of the process, and then

kill -s signal pid(number)

However, I'd like to find a more interactive and general way to do this if possible.

I'd like to send a signal to a specific process from the command line. I'd like to not need to print the PID of the process I want to signal, but rather use a way that the code understands which process should be signaled.

Other than that I'd like to understand exacly what the kill command does.

  • Does it kill the process that signals?
  • Does it kill the process where it's called?
  • If it kills a process it means that it's similar to do exit(0), or does the process resume after the signal is sent back?
like image 712
André Almeida Avatar asked Oct 20 '15 14:10

André Almeida


1 Answers

As far as I understood your question you want to signal a process by its name, not by its PID. This can easily be achieved by combining the two commands:

kill -s signal $(ps -C executable)


Does it kill the process that signals?

kill can kill. It doesn't necessarily.

From man kill:

The command kill sends the specified signal to the specified processes or process groups.

That means, the kill command is used to **send any signal in general.

If it kills a process it means that it's similar to do exit(0), or does the process resume after the signal is sent back?

From here:

The SIGKILL signal is used to cause immediate program termination. It cannot be handled or ignored, and is therefore always fatal. It is also not possible to block this signal.

If a process receives the SIGKILL signal, it terminates immediately (no destructors called, no cleanup done). The only processes that do not terminate are uninterruptible processes.


A full list of signals available on Linux is found here.

like image 175
cadaniluk Avatar answered Sep 29 '22 00:09

cadaniluk