LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to place a process to the runqueue? (https://www.linuxquestions.org/questions/programming-9/how-to-place-a-process-to-the-runqueue-548525/)

archieval 04-24-2007 03:17 AM

How to place a process to the runqueue?
 
Hello everyone! I would just want to ask how can I place a user process to a runqueue, so that when a kernel process invoked schedule(), it can be executed provided that it has a higher priority? what functions should I use?

Thanks!

theNbomr 04-24-2007 01:29 PM

You would use the exec() system call. From there, it is up to the kernel to schedule its execution. You can influence the priority of the process using renice. After that, I don't think you can affect how the kernel manages the process.

--- rod.

archieval 04-24-2007 08:18 PM

When I execute exec(), will it be executed right away? Is there other system call to make it somewhat suspended from execution, but in an interruptible state? I have tried to use sched_yield() but it is not yielding. :(

theNbomr 04-24-2007 11:45 PM

Okay, you've pointed me to a whole host of system calls that I didn't know about. sleep() can be interrupted by signals. Is that the level of suspension you want?
I think you are probably already more acquainted with the subject than I am. What are you attemping to accomplish with these low-level tinkerings?
--- rod.

archieval 04-25-2007 12:39 AM

Quote:

Originally Posted by theNbomr
Okay, you've pointed me to a whole host of system calls that I didn't know about. sleep() can be interrupted by signals. Is that the level of suspension you want?

Somewhat yes, but I don't want it to be time dependent. I want it to be just waiting. I have tried using semaphores but of course when the scheduler in the kernel space is invoked, it will execute the waiting task, but it is waiting for a semaphore. I don't know where to release the semaphore. I am using the SCHED_FIFO policy on the two tasks so that only one will be active unless one yields the cpu. But I have failed on doing this. If only sched_yield will work properly. :(

theNbomr 04-25-2007 09:27 AM

So you have two (or more) processes which you want to run in mutual exclusivity? If yes, isn't this the exact purpose of semaphores? I'm not sure you can do anything that guarantees that one process deferring to another will immediately cause a context switch. That is the domain of the scheduler.

Where you say:
Quote:

I have tried using semaphores but of course when the scheduler in the kernel space is invoked, it will execute the waiting task, but it is waiting for a semaphore
this doesn't sound quite right. As I understand it, a process blocked on a semaphore will not execute, which is how semaphores become a big efficiency gain vs. busy-waiting on a flag. Have I misunderstood you?

--- rod.

archieval 04-25-2007 10:05 PM

Yes you are correct. I used the semaphore in the user space. But I don't know where to release it since the other task that should release it is in kernel space. Now I have realized, I must make the first task to enter the kernel space and wait for the semaphore there rather than the user space so that the other task can release it in the same kernel space. Now if these two task are in kernel space, is it guaranteed that when the first task calls the schedule() it will context switch? and to be able to go back to the first task, all I have to do is call schedule() again on the other task?

Thanks! :)

theNbomr 04-26-2007 10:11 AM

Okay, I will bow out here, because I have no expertise in kernel level programming. You are trying to do something that is somewhat unorthodox, to be sure. Passing information from kernel space to userspace is outside that sphere of most programmer's knowledge.
Two things that I would suggest to you:
Re-post your questions on a forum or newsgroup dedicated to kernel programming.
Look at the fuse (filesystem in userspace) package. It's primary purpose is to export kernel level 'stuff' to userspace, and it seems likely to provide examples of how to do what you are trying to do.

Good luck with your project.

--- rod.

archieval 04-26-2007 09:35 PM

Ok thanks! :) I am also not expert in this that is why I have this problem for 2 weeks already :(


All times are GMT -5. The time now is 03:53 AM.