5

Send the signal to be processed from the command line

 2 years ago
source link: https://www.codesd.com/item/send-the-signal-to-be-processed-from-the-command-line.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Send the signal to be processed from the command line

advertisements

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?

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK