ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
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?
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.
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.
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.
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.
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?
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?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.