week 2 of teaching - process and threads

processes

PID, name, user running it, files related, parts of CPU program counters that are related to the execution (e.g. PSW and program counter) are examples of metadata stored for processes execution

reasons for process creation:

  1. System initialisation
  2. a running process wants to start a new process,this is done via a system call
  3. user request to create a new system ll
  4. a new batch job

In POSIX systems fork() is the sys-call, in windows it’s done with CreateProcess

processes are hierarchical so a process created by another one is then it’s “child” processes. It is an exact clone in terms if memory image, program counter, open resources and environment variables. However the address space is different, the do not share the space that these objects are stored in. memory address operator calls to the objects may be the same, but these virtual memory address map to different physical addresses.

processes can be terminated for a couple of reasons

ReasonDescriptionVoluntary/Involuntary
normal exitthe process reaches the end of instructionsVoluntary
error exitthe process experience’s an error, that is handled in code and leavesVoluntary
fatal errorI/O operation may fail, a resource might be busy or a page erorr could occurInvoluntary
killedanother process can kill another example: a user uses the “kill” command in shellInvoluntary

There are three process states

StateDescription
RunningCurrent process running
Readyrunnable, but not currently scheduled
Blockedunable to run, it might be waiting for another process to finish, or it could be waiting for some resource to be free

In process based operating systems there is a hierarchy of threads, at the top is the process that deals with scheduling an interrupts.

for every new processes, a new entry in the process table is created

threads

while processes are able to give us multiprogramming, sometimes parallelism while sharing address space can be beneficial. threads provide us this ability.

creating a user thread is faster as we need not rely on system calls to do it. switching is also faster (as long as its within the same process) since the entire memory image does not need to be reloaded.

ways of implementing threads

User levelkernel level
The OS has no knowledge of the threadsthread table is in the OS layer
no need for low level thread supportno need for runtime system
needs a run time systemmanaged by and implemented at the OS layer
each process requires it’s own thread table (lighter weight)can use blocking system calls easily within threads
thread table is managed by the runtime systempage faults to not effect other threads
switching is fast as it’s done with local callscreation via system calls is slower
better control over thread schedulingyou do need to deal with fork() semantics
a system call will block all other threads in process, this is a large disadvantage as this is very common behaviorsignal handling is a larger concern as each processes will have to handle which threads the interrupt is passed to

however, there is a third option avaible: “Hybrid threads” this way, a single kernel level thread can have multiple software threads contained within it

popover threads also are a thing, these are threads that are created to handle new messages within a process

issues with threads when transitioning single threaded code into multithreaded:

Back to notes...

click here to go back to more