-   Linux - Embedded & Single-board computer (
-   -   How to receive the signal multiple times in user space without terminating it? (

pobitro 06-19-2011 02:25 PM

How to receive the signal multiple times in user space without terminating it?
I want to write a program wher a process in user space sends its process id which is received in the kernel space and a
real time signal is send from the kernel space to that user space process.
The following program works fine; but the problem is the user-space process terminates immediately after receiving the
signal. Also, if we just write sig.sa_flags |=SA_RESTART;
instead of writing sig.sa_flags |= SA_SIGINFO;
sig.sa_flags |=SA_RESTART; then it is causing segmentation fault.

Q1: Is there any way we can receive the signal multiple times in the user space without terminating the process?
Q2: What is the reason for this segmentation fault?

/*======================part of Kernel code which sends the signal=======*/
#define SIG_TEST 44 // (real-time signal)

static int raise_mySignal()
{ struct siginfo info;
struct task_struct *t;
info.si_code = SI_QUEUE;
printk(KERN_INFO "********Process id: %d", user_pid);
t= pid_task(find_vpid(user_pid),PIDTYPE_PID);//user_pid has been fetched successfully
if(t == NULL){
printk("no such pid\n");
return -ENODEV;
return 0;

/*===========================Receiver Prg============================================================= */
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

#define SIG_TEST 44

void receiveData(int n, siginfo_t * info, void *unused) {
printf("received value %i\n", info->si_int);

int main ( int argc, char **argv ) {
int configfd; char buf[10];

/* setup the signal handler for SIG_TEST
* SA_SIGINFO -> we want the signal handler function with 3 arguments */
struct sigaction sig;
sig.sa_sigaction = receiveData;
sig.sa_flags |= SA_SIGINFO;
sig.sa_flags |=SA_RESTART;
//sig.sa_flags = SA_RESTART;

sigaction(SIG_TEST, &sig, NULL);

configfd = open("/sys/kernel/debug/signalconfpid", O_WRONLY);
if(configfd < 0) {
perror("***unable to open");
return -1;
sprintf(buf, "%i", getpid());
if (write(configfd, buf, strlen(buf) + 1) < 0) {
return -1;
return 0;

All times are GMT -5. The time now is 03:15 PM.