Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am newbie in Linux and also with c language, but i am working on a project. so i have to do it
I am unknown of making communication between kernel module and user space..
I have got a kernel module, and implemented some of my scenarios.
* If any network card fails then i get the notification (This is working for kernel module)
Here is a snapshot for kernel module where i am able to get the process id:
int nRemoteId, nLocalHostId;
unsigned char nNodeAvailable, bNetIsSplitted = 1;
..
..
if (nNodeAvailable > 0)
{
// Update Data-Path from PORT_A to PORT_A
if (pHbmList[nRemoteId].pathAA <= 0) {
gNetInfo.pConn[nRemoteId] &= 0xFE;
printk ("\t[%d].PORT_A <--> [%d].PORT_A is not available\n", nLocalHostId, nRemoteId);
id = get_current();
printk("Kernel PID : %d", id);
...
..
}
Now I am not sure either this is proper way or not. but i am able to get pid for each time failure in communication..
Now i have to do some tasks and i have no idea about this:
1. I need to transfer that information (for which i got the process id) to Userspace
2. After receiving the information on userspace i will transmit that information on to the user space of the other NODE via TCP/IP or UDP/IP.
Any suggestions or any example resembling to this scenario will be very much help full for me..
So you are not familiar with linux, with c and with kernel.
Just a hint: the kernel cannot communicate itself with the userspace, but a userspace program can ask the kernel to provide some information. So you need to write a c program which will use this kernel module to get info.
There are functions named "copy_from_user" and "copy_to_user" provided in the "kernel API documentation".
Thank you anisha kaul..
I actually developed further a userspace daemon also.
Here is my another post about that, with lots of confusion to communicate betweeen userspace and kernel using signals: http://www.linuxquestions.org/questi...kernel-943991/
I am not a good programmer of C and also not so much familiar with Linux programming. everything there is new for me, i have just assigned a task by my professor which i am trying to complete.
Make me correct if i am creating wrong code also try to make it complete or give me some related example:
Quote:
/*Virtual Interface*/
int vif_ioctl (struct net_device* dev, struct ifreq *ifr, int cmd)
{
int ErrCode = 0;
struct pid_t pid;
switch (cmd) {
case SIOCSAFEDEVGETINFO:
/* some code */
break;
case SIOCSAFENETGETINFO:
/* some code */
case SIOCSAFEGETPIDINFO:
printk ("Get PID Info was callled. \n");
copy_from_user(pid, ?? , ??) //////////////////What i need to give arguments here in this function/////
break;
}
further in the kernel module following code is also implemented:
Quote:
..
static pid_t id;
int result;
..
int network_response()
{
...
...
if (x = 1)
{
printk("Failure of network.")
result = kill_proc(id, SIGUSR1,1);
printk("\nReporting failure detection %d\n", result);
}
if (x = 2)
{
printk("Failure of Node is detected.")
result = kill_proc(id, SIGUSR1,1);
printk("\nReporting failure detection %d\n", result);
}
}
I am confused that how kernel space will capture SIGUSR1 signals from userspace
May be my all discussion is not so much technical, or there you can find many mistakes in code. But pardon me I am not a technical person with this kind of stuff..
If any sample code or suggestions you have then I will be happy to hear that..
the signal handler is part of the user space code. The kernel only sends the signal to the process, but it is handled by the process itself.
kill_proc will send a signal and you need to implement a signal handler to catch it. see here: http://www.gnu.org/software/libc/man...-Handling.html (and defining handlers)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.