LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-11-2015, 11:34 AM   #1
david_8274
Member
 
Registered: Jun 2013
Location: California
Distribution: Ubuntu, Fedora
Posts: 74

Rep: Reputation: Disabled
Sending kernel signal to userspace with data


Hi,

I am trying to send a kernel signal on event to userspace with data.
Currently I am able to send a signal to user space without data (with the kernel signal module struct siginfo and send_sig_info()).
I read online about the possibility of including a 32-bit value in the data structure (I guess the term is "realtime kernel signal"), but was not able to find any sample code as reference.
Can someone point me to a sample code for this purpose?

Thanks,
Wei Xu
 
Old 11-11-2015, 12:34 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,609

Rep: Reputation: 702Reputation: 702Reputation: 702Reputation: 702Reputation: 702Reputation: 702Reputation: 702
There's a reason why you won't find any sample code for this. It's a terrible idea.

A simpler way might be to have your program make a call into your kernel module. "Read" or "ioctl" are frequent choices for this. The call blocks until the kernel event that you want to signal. Then the kernel fills the user space argument with the data that you want to return and exits. User space processes the data. When it is ready for more, it makes the call again. This way you don't have all the overhead of switching contexts several times, the signal queue, the scheduler, sleep and wake, and all the code for race conditions and missed events.
 
Old 11-11-2015, 12:35 PM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,087
Blog Entries: 10

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
No such way without rewriting the kernel signal utilities. The signal IS the message.

The siginfo_t structure contains system populated information such as the process ID which generated the signal, errno value, and so forth, but no data that is user program modifiable without having to rewrite the kernel signal handler and modifying it such that there is additional components to that structure, a different structure altogether, or re-using some part of that structure in a different manner.

There are different manners of interprocess communications (IPC). It all depends what type and size of data you need to transit and between which process types. There are just normal IPCs, file or also named pipes, signals, FIFO's, shared memory. In many cases you can use a signal to indicate that a message is available.
 
Old 11-11-2015, 04:10 PM   #4
david_8274
Member
 
Registered: Jun 2013
Location: California
Distribution: Ubuntu, Fedora
Posts: 74

Original Poster
Rep: Reputation: Disabled
Hi,

From the following link:

http://wiki.tldp.org/kernel_user_space_howto

I read the following statement:

There are two types of signal APIs in user space: "normal" signals which do not have any data, and "realtime" signals which carry 32 bits of data

Is it a valid statement?

Thanks,
Wei Xu



Quote:
Originally Posted by rtmistler View Post
No such way without rewriting the kernel signal utilities. The signal IS the message.

The siginfo_t structure contains system populated information such as the process ID which generated the signal, errno value, and so forth, but no data that is user program modifiable without having to rewrite the kernel signal handler and modifying it such that there is additional components to that structure, a different structure altogether, or re-using some part of that structure in a different manner.

There are different manners of interprocess communications (IPC). It all depends what type and size of data you need to transit and between which process types. There are just normal IPCs, file or also named pipes, signals, FIFO's, shared memory. In many cases you can use a signal to indicate that a message is available.
 
Old 11-11-2015, 05:19 PM   #5
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,609

Rep: Reputation: 702Reputation: 702Reputation: 702Reputation: 702Reputation: 702Reputation: 702Reputation: 702
The man page for sigqueue shows how to receive this data in your sigaction handler.
 
Old 11-11-2015, 05:57 PM   #6
david_8274
Member
 
Registered: Jun 2013
Location: California
Distribution: Ubuntu, Fedora
Posts: 74

Original Poster
Rep: Reputation: Disabled
Hi smallpond,

I guess sigqueue() is used to send signal from one user space process to another user space process. However, I wish to send signal from kernel to a user space process. Am I wrong about that?

Thanks,
Wei Xu

Quote:
Originally Posted by smallpond View Post
The man page for sigqueue shows how to receive this data in your sigaction handler.
 
Old 11-11-2015, 06:20 PM   #7
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,609

Rep: Reputation: 702Reputation: 702Reputation: 702Reputation: 702Reputation: 702Reputation: 702Reputation: 702
Your code will likely be the first to do it this way That should tell you something.

http://lxr.free-electrons.com/source/fs/signalfd.c#L138
Quote:
/* This is not generated by the kernel as of now. */
 
  


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
Catch signal from userspace to kernel space XDimensioN Programming 1 10-27-2014 06:34 AM
how is kernel notifying userspace when data arrives on a socket/fd jork Linux - Kernel 2 06-25-2010 04:57 AM
Efficient kernel<->userspace data transfering maverik Programming 2 05-31-2008 03:24 AM
Passing IP options data to kernel from userspace kaushik1 Programming 2 12-27-2007 12:38 AM
a question about kernel copy userspace data linwenyuan Programming 0 03-28-2007 10:55 AM


All times are GMT -5. The time now is 12:55 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration