LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 09-07-2005, 11:36 AM   #16
vishamr2000
Member
 
Registered: Aug 2004
Posts: 210

Original Poster
Rep: Reputation: 31

Hi to all,

No i don't want a two way communication between Prog1.c and Prog2.c. Prog1.c just sends the signal and it continues it's execution in parallel, without having to wait for Prog2.c to finish. Prog1.c kind of sends the signal and forgets about it.

One thing though..is it possible to send a signal from Prog1.c and not have Prog1.c waits for the return. Can we have a signal that does not return to the program that generated and sent it? I want to do sth like this: Prog1.c issues the signal and then continues with the remaining statements. Is this possible? How can I do that?

Any input will be very much appreciated..

Warm regards,
Visham
 
Old 09-07-2005, 11:43 AM   #17
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
You want a communication (kill) from the kernel (Prog1) to a userland process (Prog2).

You want too the kernel (Prog1) to call a userland process (pidof) to retrieve a process ID.

You have to think carefully on how you want to achieve both of these tasks, as you are on your own when writing kernel code, no libraries, no (g)libc are available and no bugs are allowed ...
 
Old 09-07-2005, 04:44 PM   #18
vishamr2000
Member
 
Registered: Aug 2004
Posts: 210

Original Poster
Rep: Reputation: 31
Absolutely correct..for the signal from kernel to Prog2.c, i'll use kill() in the kernel code and sigaction in Prog2.c to catch it.

For the retrieval of the pid of Prog2.c by the kernel program, i can use global variables to store the value of getpid() in Prog2.c and then access it from kernel code.

One question though..how come you have no libraries, no (g)libc are available when doing kernel coding? Then how are we supposed to write programs? I didn't know abt this issue and would be grateful if you could enlighten me on this. Also if you have good sources of info on this and kernel coding, do let me have them.

Warm regards,
Visham
 
Old 09-07-2005, 05:34 PM   #19
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
i'll use kill() in the kernel code
Hmm, I already wrote a couple of times, but let me do it once again:

You are not going to call kill() from the kernel, because you have no access to libraries and system calls
Quote:
For the retrieval of the pid of Prog2.c by the kernel program, i can use global variables to store the value of getpid() in Prog2.c and then access it from kernel code.
Well, this is even harder, how will the kernel access these "global variables" ?
A global variable is global to all functions of a process, but not between processes, and even less between a userland process and the kernel.
Quote:
One question though..how come you have no libraries, no (g)libc are available when doing kernel coding?
Kind of chicken and egg problem, the kernel need to embed everything it needs and not rely on services provided by ... the kernel.
Quote:
Then how are we supposed to write programs?
Programs and kernel code/modules are different beasts.
Quote:
Also if you have good sources of info on this and kernel coding, do let me have them.
I already post a link to a site you seem to have overlooked.
 
Old 09-08-2005, 09:30 AM   #20
vishamr2000
Member
 
Registered: Aug 2004
Posts: 210

Original Poster
Rep: Reputation: 31
Hi,

>You are not going to call kill() from the kernel, because you have no access to libraries and system calls

I intend to add a few lines of code to a function in iptables (kernel code). Do you mean to say that I will not be able to use the kill() function there? If no, what do you suggest me to do about what I want?

>Well, this is even harder, how will the kernel access these "global variables" ? A global variable is global to all functions of a process, but not between processes, and even less between a userland process and the kernel.

Some one told me that we can declare global variable in /etc/profiles. Variables defined there can be accessed from anywhere - both kernel space and userspace code. To read/ write to that variable, i will have to employ semaphores i believe.

>I already post a link to a site you seem to have overlooked.

No, i didn't overlook it..it's actually a website that i had used in the past but had forgotten about lately..thx for reminding me.

Warm regards,
Visham
 
Old 09-08-2005, 09:44 AM   #21
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
J
 
Old 09-08-2005, 11:20 AM   #22
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Do you mean to say that I will not be able to use the kill() function there?
Exactly. kill is a system call, and you can't use system calls from inside the kernel (Hmm, didn't I wrote that already ...).
Quote:
If no, what do you suggest me to do about what I want?
Do it the way around, have a userland process communicating with the kernel. One way to do it would be using the procfs facility.
Actually, my best suggestion would be to discourage you to start such a project which seems unreasonably overcomplicated. Kernel programming is a job for skilled veterans.
Quote:
Some one told me that we can declare global variable in /etc/profiles. Variables defined there can be accessed from anywhere - both kernel space and userspace code.
The one who told you that is confusing very different variables and has no clue about what means kernel space. Environment variables set in /etc/profiles are anyway not at all shared between processes, and definitely outside kernel scope.
 
Old 09-08-2005, 12:18 PM   #23
vishamr2000
Member
 
Registered: Aug 2004
Posts: 210

Original Poster
Rep: Reputation: 31
First of, many many thx for taking the time to explain all this to me..otherwise i would have been losing so much time on it.

One thing though..how does iptables kernelspace code iteract with iptables userspace code? Does it use the procfs facility?

And are there no instances in Linux where the kernel communicates with a userspace program (in terms of error messages, interrupts...)?

Warm regards,
Visham
 
Old 09-08-2005, 02:36 PM   #24
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
how does iptables kernelspace code iteract with iptables userspace code?
It is normally the way around.
Quote:
Does it use the procfs facility?
I don't think so, but it uses getsockopt() and setsockopt().
Quote:
And are there no instances in Linux where the kernel communicates with a userspace program (in terms of error messages, interrupts...)?
The kernel is a facilitator for userspace process communication. The scheduler is also responsible of the order and time slots each process will be granted the CPU. The kernel do send error messages to processes, but it can terminate them, dump cores, swap them out, but this can hardly be considered as communication. Of course error codes can be returned in reply to a system call, but the kernel is not the initiator of the dialogue.
 
Old 09-08-2005, 02:58 PM   #25
vishamr2000
Member
 
Registered: Aug 2004
Posts: 210

Original Poster
Rep: Reputation: 31
Quote:
The scheduler is also responsible of the order and time slots each process will be granted the CPU.
How does the scheduler interrupt a running process and then schedule another? Does the scheduler sends a SIGINT?

Quote:
The kernel do send error messages to processes
Can we force the kernel to send sth to a process. If yes, can't we send sth to my userspace program so that when it receives it, it knows that it has to execute.

Regards,
Visham
 
Old 09-08-2005, 03:16 PM   #26
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
How does the scheduler interrupt a running process and then schedule another? Does the scheduler sends a SIGINT?
It doesn't send a SIGINT, only processes send signals, the scheduler (in the case of preemptive scheduling) is just interrupting instantly the process, in a way absolutely transparent to the process which is unaware of it, and managing properly the context change to allow another process to take place.
Quote:
Can we force the kernel to send sth to a process. If yes, can't we send sth to my userspace program so that when it receives it, it knows that it has to execute.
You do not force the kernel to do something, but you can code part of of the kernel or modules that will do what you want, assuming you know enough of the kernel internals to do it, but this is poor design. Sending something to a process would imply that this process has code to receive and react to the message, which the kernel doesn't know. Logically, it is the process the one that should ask the kernel for information.
 
Old 09-08-2005, 04:17 PM   #27
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495

Rep: Reputation: 85
the command "top" without quotes gets the processes and proabably their pid too. You can push control + escape to get a thing like task manager.
 
Old 09-09-2005, 12:48 AM   #28
vishamr2000
Member
 
Registered: Aug 2004
Posts: 210

Original Poster
Rep: Reputation: 31
Hi,

When i was saying that the kernelspace program has to send a signal to the userspace program, i didn't actually had in mind the use of signals or other system calls at first. Now, thx to you, I know it's not possible. I just wanted the kernelspace program to tell the userspace program to start its execution. This is the part I don't know how to do. This is where the problem lies.

Quote:
Sending something to a process would imply that this process has code to receive and react to the message, which the kernel doesn't know.
I don't what and how we can send. If we manage to send anything, then we can make the userspace program catch it. I don't want a 2-way communication between these two programs. The kernelspace program just send "the thing" and then continues its execution. Both execute independently. No results to be returned to the kernelspace program. It's only 1-way communication. It's as if the kernelspace program schedules the userspace program to run.

What do you think?

To fakie_flip: I don't think 'top' will work in kernelspace. Thx anyways..

Warm regards,
Visham
 
Old 09-09-2005, 01:26 AM   #29
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
The kernelspace program just send "the thing" and then continues its execution. Both execute independently.
You still view the kernel as an ordinary process, which it is not.

You can have the kernel sending something through a device driver (/proc for example).

If a process reads that piece of information, you have a communication from the kernel to a process.
 
Old 09-09-2005, 01:35 AM   #30
vishamr2000
Member
 
Registered: Aug 2004
Posts: 210

Original Poster
Rep: Reputation: 31
Yes..we can try to do that..

Do you have idea abt wat we can send? Do have any example of how to do it?

Pls do let me have it.

Warm regards,
Visham
 
  


Reply



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
Getting PID of running process in C/C++ laikos Programming 16 10-30-2015 06:16 PM
Start a Process with dedicated PID murder Linux - Newbie 5 08-15-2005 03:49 PM
how to get more process' info according to its PID? iclinux Programming 1 02-05-2005 05:30 AM
Get Next PID of Process Tree zer0python Programming 7 11-26-2003 11:56 AM
How to find the pid to stop a process.... vous Linux - Networking 6 08-14-2003 04:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:37 PM.

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