Linux processes can send signals to each other to send some notifications, the signal can carry data (4 bytes), specifically see the Sigqueue function.
If you want to use a custom signal to send data, the normal signal only reserved two signals USER1 USER2, if two is not enough, Linux also provides real-time signal this kind of thing.
The user can define his own signal and send it, but the number is not infinite at present about 32 can be used.
Test code:
#include <iostream> #include <stdio.h> #include <string.h> #include < signal.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h># include <cygwin/signal.h> using namespace std; int sig_test1 = Sigrtmin + 1;int sig_test2 = sigrtmin + 2; static void sig_ HDL (INT&NBSP;SIG,&NBSP;SIGINFO_T&NBSP;*SIGINFO,&NBSP;VOID&NBSP;*PTR) { if ( SIG&NBSP;==&NBSP;SIG_TEST1) { printf ("I get sig test1 %d \n ", siginfo->si_value); } if (SIG&NBSP;==&NBSP;SIG_TEST2) { printf ("I get sig test2 %d \n ", siginfo->si_value); }} int main () { struct sigaction st; memset (&st, 0, sizeof (ST)); st.sa_flags = sa_siginfo; st.sa_sigaction = sig_hdl; sigaction (sig_test1, &st, null); st.sa_sigaction = sig_hdl; sigaction (SIG_TEST2, &st, NULL ); sigval t; t.sival_int = 1; sigqueue (Getpid (), sig_test1, t); t.sival_int = 2; sigqueue (Getpid (), sig_test2, t); return 0;}
Output:
[Root@centos ~]#./a.out
I get SIG Test1 1
I get SIG Test2 2
Use signals for inter-process communication between Linux