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-^?;
Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.Get the Linux Sysadmin Course Now!
If you enjoyed this article, you might also like..
|
|
|
|






My name is Ramesh Natarajan. I will be posting instruction guides, how-to, troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write articles that will either teach you or help you resolve a problem. Read more about
{ 4 comments… read them below or add one }
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