LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 06-19-2011, 03:25 PM   #1
pobitro
LQ Newbie
 
Registered: Jun 2011
Posts: 1

Rep: Reputation: Disabled
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_signo=SIG_TEST;
info.si_int=1;
info.si_code = SI_QUEUE;
printk(KERN_INFO "********Process id: %d", user_pid);
rcu_read_lock();
t= pid_task(find_vpid(user_pid),PIDTYPE_PID);//user_pid has been fetched successfully
if(t == NULL){
printk("no such pid\n");
rcu_read_unlock();
return -ENODEV;
}
rcu_read_unlock();
send_sig_info(SIG_TEST,&info,t);
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) {
perror("fwrite");
return -1;
}
sleep(100);
return 0;
}
 
Old 07-12-2016, 09:54 AM   #2
aragats
LQ Newbie
 
Registered: Jul 2016
Posts: 1

Rep: Reputation: Disabled
Explicit assignment of those two flags works fine here:

sig.sa_flags = SA_SIGINFO | SA_RESTART
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
user-define signal handler & coredump for signal 11(SIGSEGV) Alexlun Linux - Software 2 05-24-2009 07:37 AM
Creating Multiple Directories in the same location in user space leebrent Linux - General 3 10-29-2007 01:14 PM
Obtaining periodic AP receive signal strength measurements wood@addanc Linux - Wireless Networking 2 06-24-2007 12:43 PM
Kppp times out with signal 15 hiredgunz Linux - Hardware 2 01-15-2005 08:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 10:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration