Commit a24b4ec

mo khan <mo@mokhan.ca>
2021-03-23 02:51:52
Add notes on threads
1 parent 491623c
Changed files (1)
doc
doc/3.md
@@ -123,4 +123,40 @@ Process Control Block
     ----------------------
 ```
 
+On Linux this is represented in `struct task_struct` in `<linux/sched.h>`.
+
 ### Threads
+
+The process model discussed so far has implied that a process is a program that performs a single `thread`
+of execution.
+
+Processes can have multiple threads of execution and thus to perform more than one task at a time.
+This is beneficial on multicore systems, where multiple threads can run in parallel.
+
+On systems that supports threads, the PCB is expanded to include information for each thread.
+
+### Process Scheduling
+
+Multiprogramming: have some process running at all times to maximize CPU usage.
+Time sharing: switch the CPU among processes so frequently that users can interact with each program while it is running.
+
+The `process scheduler` selects an available process for program execution on the CPU.
+A single-processor system, there will never be more than one running process. The rest will
+have to wait until the CPU is free.
+
+#### Scheduling Queues
+
+As processes enter the system, they are put into a `job queue`, which consists of all processes in the system.
+The processes that are residing in main memory and are ready and waiting to execute are kept in the `ready queue`.
+This queue is usually stored as a linked list.
+The doubly-linked list contains process control block nodes/structs. Each PCB points to the next PCB in the ready queue.
+
+The list of processes waiting for a particular I/O device is called a `device queue`.
+Each device has its own device queue.
+
+A new process is initially put in the ready queue. It waits there until it is selected for execution,
+or `dispatched`. Once the process is allocated the CPU and is executing, one of the several events could occur:
+
+* The process could issue an I/O request and then be placed in an I/O queue.
+* The process could create a new child process and wait for the child's termination.
+* The process could be removed forcibly from the CPU, as a result of an interrupt and be put back in the ready queue.