Question: How do I send signal to another process? Can you explain me all available options to send signals to a process in UNIX / Linux environment?
Answer: You can send various signals to processes using one of the methods explains in this article.
1. Send Signal to a Process Using Kill
Use kill command to send a signal to a process. For example, if you want to send USR1 signal to the process “a.out”, do the following.
$ ps -C a.out PID TTY TIME CMD 3699 pts/1 00:00:00 a.out $ kill -s USR1 3699
Note: Refer to 4 Ways to Kill a Process – kill, killall, pkill, xkill.
2. Send Signal to a Process from Another Process
You can use the UNIX system call kill (from a C program) to send signal from one process to another. The following C code snippet shows how to use the kill command.
Kill system call takes two arguments: 1) the PID (process id) of the process that needs to be signalled 2) the signal that needs to be send to the process. Kill command returns 0 when it is successful.
int send_signal (int pid) { int ret; ret = kill(pid,SIGHUP); printf("ret : %d",ret); }
3. Send Signal to a Process from Keyboard
When a process is running on the terminal, you can send signal to that process from the keyboard by using some specific combination of keys. The following are couple of examples.
- SIGINT (Ctrl + C) – You know this already. Pressing Ctrl + C kills the running foreground process. This sends the SIGINT to the process to kill it.
- You can send SIGQUIT signal to a process by pressing Ctrl + \ or Ctrl + Y
You can view the key mappings that sends specific signal to a process using the “stty -a” command as shown below.
$ stty -a | grep intr intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?;
Comments on this entry are closed.
Thanx alot sir, for very helpful information…..
Info about signals 0 and -1 may be usable here.
hello sir how to install vlc in linux 5
Hi.
intr and quit are signals, I think, the rest are not. Specifically, there is no shortcut to send a kill signal.
Also I’d like to add the other useful shortcut: Ctrl+Z for SIGSTOP. Followed by “bg”, it can be used to transfer a foreground process to the background.
Regards,
Felix
Second option from command line, may be useful 🙂
pkill -USR1 -n -x