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:
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
Reason | Description | Voluntary/Involuntary |
---|---|---|
normal exit | the process reaches the end of instructions | Voluntary |
error exit | the process experience’s an error, that is handled in code and leaves | Voluntary |
fatal error | I/O operation may fail, a resource might be busy or a page erorr could occur | Involuntary |
killed | another process can kill another example: a user uses the “kill” command in shell | Involuntary |
There are three process states
State | Description |
---|---|
Running | Current process running |
Ready | runnable, but not currently scheduled |
Blocked | unable 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
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.
Pthreads
(aptly named)ways of implementing threads
User level | kernel level |
---|---|
The OS has no knowledge of the threads | thread table is in the OS layer |
no need for low level thread support | no need for runtime system |
needs a run time system | managed 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 system | page faults to not effect other threads |
switching is fast as it’s done with local calls | creation via system calls is slower |
better control over thread scheduling | you 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 behavior | signal 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:
click here to go back to more