Sending Signals With payload.
1) we can send signal from one process to other along with data.
2) Data can be an int or pointer to some location.
3) For pointer both process should have access to that location, In case of integer,
data is part of the signal.
4) There is no provision to include the payload in signal which is sent from kernel.
Example:
file: first.c
#include
#include
void sighandler(int sig, siginfo_t *info, void *arg)
{
printf("In Handler value %d\n", info->si_value.sival_int);
}
{
printf("In Handler value %d\n", info->si_value.sival_int);
}
main()
{
struct sigaction sa;
int ret;
{
struct sigaction sa;
int ret;
sa.sa_sigaction = sighandler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART | SA_SIGINFO;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART | SA_SIGINFO;
if((sigaction(SIGUSR1, &sa, NULL)) == -1) {
printf("Can't register handler\n");
}
for(;;) {
pause();
}
printf("Can't register handler\n");
}
for(;;) {
pause();
}
}
file second.c
#include
#include
#include
#include
#include
main(int argc, char *argv[])
{
sigval_t value;
int ret, pid;
{
sigval_t value;
int ret, pid;
if(argc < 2) {
printf("%s \n", argv[0]);
return;
}
printf("%s
return;
}
pid = atoi(argv[1]);
value.sival_int = atoi(argv[2]);
ret = sigqueue(pid, SIGUSR1, value);
value.sival_int = atoi(argv[2]);
ret = sigqueue(pid, SIGUSR1, value);
if(ret) {
perror("sigqueue\n");
}
perror("sigqueue\n");
}
}
Comments