Back to Index
Multitasking is one of the super-special things about BAOS, but aslo one of the most complicated things the OS does. What actually happends is the following:
NOTE: A program can also switch to the next process in this table by calling the nextproc function. This has however one side affect. In contrary to what some people may think, the next process will hev less execution time. This is because the multitasking system will switch to the next after a fixed amount of time, however a bit of this time is already consumed by the process that called nextproc, so after process-switching the amount of time it has is less then under normal circumstances.
NOTE2: There is one exception on the note above. This is when the timer-interrupt is actually trigered while the process-switching routine is being executed. Because you never want to let such a thing happen (switching while switching, this would mean that the process-switching routine data would be put into the process table and may result in a system crash) interrupts are being disabled while doing a precess-switch. Becouse of this the next process would have a little bit more execution time (since the process-switching was already done before the timer was triggered.
It's not sure what layout the process table will have at the end, but currently it has the following layout:
|Byte||0||1||2 - 3||4 - 15|
|Description||PID||Running / Sleeping||Stack Pointer||Process Name|
|PID||The Process IDentifier, an unique number (1-255) that identifies the process for the system.|
|Running / Sleeping||This is the state of a process. Under normal circumstanced, a process is running (1), but if a process is sleeping (0), the system will never switch to it, which can be usefull together with timers or software-triggers.|
|Stack Pointer||When switching processes, the Stack Pointer Register (SP) is loaded from or stored into here.|
|Process Name||A process can give itself a name (most of the time the system will do this when starting a program, however a program may change it to anything) by calling the setprocname function. As long as the name (including the trailing zero-byte) is not longer than 12 bytes.|
You can start a process by calling the newproc function. However most of the time you will probably starting programs instead of processes. Starting programs also includes loading a program into the memory, parsing memory locations, etc.
When the newproc function is called, the following things happen:
Stopping processes can be done in three different ways:
NOTE: in the last 2 ways of stopping a process, endproc will clean up all the mess the process leaves when "dissapearing", such as freeing memory.