LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-27-2007, 02:30 PM   #1
mtb001
LQ Newbie
 
Registered: Aug 2007
Posts: 2

Rep: Reputation: 0
How to create new process from within loadable kernel module?


Through online searching I (a linux newbie) have been able to create a LKM that registers to be probed when specified USB devices are connected.

The USB devices contain a number of interfaces that are each setup for serial communication.

To hide the /dev/tty... implementations from the user space processes that will use these interfaces for communication, I'd like to have the LKM create a user space process for each interface. The newly created processes would be used via some form of IPC to provide communcation over the single interface it supports. Conversely, when a specified USB device is disconnected, all processes supporting the communication over that devices interfaces would be killed.

I've successfully experimented with fork() and execl() from a user space process but have not been able to build these calls into my LKM.

Is it possible to do what I am proposing from within an LKM?
 
Old 08-27-2007, 04:22 PM   #2
gkiagia
Member
 
Registered: Oct 2003
Location: Greece
Distribution: Debian sid
Posts: 248

Rep: Reputation: 30
I don't really know what you have in mind, but I've recently seen a kernel module that spawns a userspace daemon via udev when it gets loaded. Actually, udev spawns the process when the module creates a /dev/something file, which /dev/something is a special file that is used for IPC between the daemon and the module. Hacking around this concept, I guess you will be able to do what you say, if I understand well what you want to do.

The module/daemon that I mention can be found here: http://mcentral.de/wiki/index.php/Userspace_tuner

Happy coding
 
Old 08-28-2007, 06:16 AM   #3
archieval
Member
 
Registered: Apr 2007
Location: Philippines
Distribution: Kubuntu, Ubuntu, CentOS
Posts: 289

Rep: Reputation: 41
To create a process in kernel space you can use kernel_thread, but I am not sure how to make the created process operate in user space.. Is it possible that you have a waiting user space task that can just be signaled anytime by your module?
 
Old 08-29-2007, 09:16 AM   #4
mtb001
LQ Newbie
 
Registered: Aug 2007
Posts: 2

Original Poster
Rep: Reputation: 0
gkiagia and archieval,

Thank you for your replies.

If there wasn't a way to create and terminate user space processes directly from the kernel module code, the next option was to have a waiting user space process that is signaled by the kernel module.

I was thinking the kernel module would signal the user space process via the creation/deletion of files that correspond to the interfaces supported by the connected/disconnected USB device. The user space process would watch for the creation/deletion of these files and create/terminate other user space processes that would each provide communication support over a single interface.

I need to take a closer look at udev to see if it can do the user space monitoring for me. From the example referenced by gkiagia, it appears udev can create a user space process when a file is created. Do either of you know if it's also capable of terminating that process if the file is removed?
 
Old 08-29-2007, 10:27 AM   #5
gkiagia
Member
 
Registered: Oct 2003
Location: Greece
Distribution: Debian sid
Posts: 248

Rep: Reputation: 30
I think that udev can also kill the userspace process, but I am not really sure.

However, as far as I've seen by experimenting with the module that I told you above, when I unload that module, the userspace daemon is killed too. I assume that this happens because the userspace daemon runs select() on /dev/tuner waiting for data to be read, without a timeout specified on select(). When /dev/tuner is removed, select() returns 0 and there is a conditional statement that checks its return value and exits the daemon.

I think it would be also possible that the kernel kills the userspace process by sending it some special data over the /dev/file that it is opened for IPC. The userspace process will be programmed to exit when it receives that data.

So, no matter how you do it, it is possible!
 
Old 08-31-2007, 11:09 PM   #6
archieval
Member
 
Registered: Apr 2007
Location: Philippines
Distribution: Kubuntu, Ubuntu, CentOS
Posts: 289

Rep: Reputation: 41
To kill the user space process, just use signal; send a signal from the kernel space module then the user space program should watch for it by sigaction.

To create a user space process while in the kernel space is a nice idea, tell me if you have succeeded in doing this cause its interesting. =)
 
  


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
how to insert a loadable module into the kernel.? moog Linux - Newbie 2 01-08-2007 08:37 AM
Help, loadable kernel module . ERBRMN Linux - General 3 10-13-2006 07:34 AM
how to add new loadable module to kernel? Mistreated Linux - Software 7 02-02-2005 10:22 AM
RedHat 9 (2.4.20-8) kernel rebuild without loadable module support RedHatDude Linux - Software 4 09-09-2003 09:32 PM
loadable kernel module brajesh Linux - General 2 01-17-2003 12:54 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration