Hi All,
I've been refering to osdev for a while now - it's an awesome resource.
I just have a bit of a question regarding software multitasking.
I have software multitasking working (very basic) on my os and can execute tasks in a round-robbin fashion. My question is: what happens when a task finishes (ie returns)??? what should happen? how should the scheduler know that the task has finished?
or is it necessary to put the task in an infinite loop and somehow send a signal to the scheduler that it has finished? - that doesn't sound very user friendly.
Sorry if this is really obvious or has already been discussed elsewhere but I couldn't find anything about it anywhere.
Cheers,
Matt
Software Multitasking - What happens when a task finishes?
Re: Software Multitasking - What happens when a task finishe
Standard operating procedure suggests that your provide a form of exit() in the API.karter16 wrote:Hi All,
I've been refering to osdev for a while now - it's an awesome resource.
I just have a bit of a question regarding software multitasking.
I have software multitasking working (very basic) on my os and can execute tasks in a round-robbin fashion. My question is: what happens when a task finishes (ie returns)??? what should happen? how should the scheduler know that the task has finished?
or is it necessary to put the task in an infinite loop and somehow send a signal to the scheduler that it has finished? - that doesn't sound very user friendly.
Sorry if this is really obvious or has already been discussed elsewhere but I couldn't find anything about it anywhere.
Cheers,
Matt
To cover those programs that just tend to "return", your program loader should make a CALL to the program's entry-point so that the final program RET returns back to that same loader (assuming no stack corruption) and follow-up with whatever clean-up code you have.
Generic Example...
Code: Select all
;Loader Code
call APP_ENTRY_POINT
;APP Returned back here... obviously... so perform cleanup...
In addition, if you want to provide some sort of return value from a process, the general way is to get the return value of main(), store it in the process information structure, and then leave the structure in memory until the process that created the process which exited calls a syscall to get the return value and then deletes the process struct. Then, you run into problems where the calling process exits without getting the return value, leading to a process structure that persists with nothing to remove it. Either you maintain a list of child process' to be removed (if they have terminated) when a parent terminates, or have it done in a separate kernel thread that runs whenever the system is otherwise idle.
Regards,
John.
Regards,
John.