When reading the APUE signal chapter, I metIn Linux, it does not work for background processes to pass signals through kill.
The specific situation is the same as that in the following link:
Http://bbs.csdn.net/topics/390335913? Page = 1 # post-395188120
Compile and execute the following signal program, and then shell command line: First let the program run in the background, get the process ID, then send the signal to the process using kill: kill-USR1 ID, but no result
#include "apue.h"static void sig_usr(int);int main(void){if(signal(SIGUSR1,sig_usr)==SIG_ERR) err_sys("can not catch SIGUSR1");if(signal(SIGUSR2,sig_usr)==SIG_ERR) err_sys("can not catch SIGUSR2");for( ; ; ) pause();}static void sig_usr(int signo){if(signo==SIGUSR1) printf("received sIGUSR1\n");elseif(signo==SIGUSR2) printf("received sIGUSR2\n");else err_dump("received signal %d\n",signo);}
Here is my solution:
This problem should be implemented in the background of linux processes. You can try this experiment in another way:
1. Add the print getpid () function to the program.
2. Run the program on the foreground
3. In the new terminal window, enter "kill-USR1 [pid]" in the new terminal window.
4. Return to the original terminal and view the experiment results.
Kill
Function Description: delete a program or job in progress.
Syntax: kill [-s <information name or number>] [Program] or kill [-l <information number>]
Note: kill can send specified information to the program. The preset information is SIGTERM (15). You can terminate the specified program. If you still cannot terminate the program, you can use SIGKILL (9) Information to try to forcibly Delete the program. The program or job number can be viewed using the ps or jobs commands.
Parameters:
-L <Information No.> If the <Information No.> option is not added, the-l parameter lists all information names.
-S <information name or number> specifies the information to be sent.
[Program] [Program] can be the PID or PGID of the program, or the work number.