Lecture 5 process concept


Published on

Published in: Education, Technology, Business
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Lecture 5 process concept

  2. 2.  Process Introduction Process States Process Control Block (PCB or TCB) Process creation and I/O Requests Schedulers
  3. 3.  A program in execution Process in memory has ◦ Text section (includes program code) ◦ Data section (global variables) ◦ Stack (contains the return address, local address, function parameters) ◦ Heap (dynamic runtime memory during the execution of process and this may vary)
  4. 4. stackheapdatatext
  5. 5.  Program is a passive entity Program stores sequence of instructions written in a file stored in the secondary memory Process is active entity which has program counter that tells the next instruction to be executed and also has a set of associated resources. Program becomes a process when the file is loaded in the primary memory ◦ Example: double click the executable file of running a.out is example of program -> process
  6. 6.  New – a process is generated Ready – multiple processes are ready to run under a CPU. Running – currently executing on the CPU Waiting – Waiting for an Event or an IO, Once the event is available, process moves to the ready state. Terminated – Process is killed or terminated
  7. 7.  Identifier: A unique identifier associated with this process, to distinguish it from all other processes. State: If the process is currently executing, it is in the running state. Priority: Priority level relative to other processes. Program counter: The address of the next instruction in the program to be executed. Memory pointers: Includes pointers to the program code and data associated with this process, plus any memory blocks shared with other processes.
  8. 8.  Context data: These are data that are present in registers in the processor while the process is executing. I/O status information: Includes outstanding I/O requests, I/O devices (e.g., disk drives) assigned to this process, a list of files in use by the process, and so on. Accounting information: May include the amount of processor time and clock time used, time limits, account numbers, and so on.
  9. 9. pid_t pid Process identifierLong state State of a processUnsigned int time_slice Scheduling informationStruct task_struct *parent This process’s parentStruct list_head child; This process’s childrenStruct files_struct *files List of open filesStruct mm_struct *mm Addresss space of this process
  10. 10. int main(){pid_t pid;pid =fork();if (pid < 0) { I* error occurred *Ifprintf(stderr, "Fork Failed");return 1;}else if (pid == 0) { I* child process *Iexeclp("lbinlls","ls",NULL);}else { I* parent process *I}wait (NULL) ;printf("Child Complete");return 0;}
  11. 11.  A process migrates among various scheduling queues throughout its lifetime Long Term Scheduler or Job Scheduler ◦ in a batch system, more processes are submitted than can be executed immediately. ◦ execute less frequently Short Term Scheduler or CPU Scheduler ◦ selects from among the processes that are ready to execute and allocates the CPU to one of them. ◦ Runs most frequently (ex: runs every 100ms)
  12. 12.  Processes are either I/O Bound or CPU Bound Long Term schedulers should have the correct mix of I/O Process and CPU Bound processes Short Term Scheduler schedules the Processes that are ready to run under the CPU So Unix and Microsoft does not have Long Term Schedulers as it more time to get executed
  13. 13.  When an interrupt occurs, the state of the process to be saved which called as context switching It depends highly on the hardware support Hardware architecture should have more number of registers as compared to more number of context switches.
  14. 14.  Reasons for IPC ◦ Information Sharing  Sharing file between processes ◦ Computational Speedup  Processes are break down in to sub-process ◦ Modularity ◦ Convenience  Individual user can work on many tasks at the same time
  15. 15.  Independent Processes ◦ No interference with other processes in the system Cooperative processes ◦ Shared Memory ◦ Message Passing
  16. 16.  Message Passing ◦ Suitable for smaller amount of data ◦ Easier to implement ◦ Usually implemented using System calls, so kernel is bothered every-time during message communication Shared Memory ◦ Faster to implement ◦ system calls are required only to establish shared- memory regions. ◦ Once shared memory is established, all accesses are treated as routine memory accesses, and no assistance from the kernel is required.
  17. 17.  Use of Producer – Consumer relations Producer will produce and consumer will consume the items produced by the producer P-C problem achieved through ◦ Unbounded buffer  No limit on the size of queue  The consumer may have to wait for new items but the producer can always produce new items. ◦ Bounded buffer  Implement like a circular Queue  Producer will wait if the queue is full  Consume will waif if the queue is empty
  18. 18. #define BUFFER_SIZE 10typedef struct {…}item;item buffer[BUFFER_SIZE];int in = 0;int out = 0;/*Buffer is empty when in==outBuffer is full when ((in+1)%BUFFER_SIZE)==out*/
  19. 19. while (true) {/* produce an item in nextProduced *Iwhile ( ((in + 1) % BUFFER_SIZE) == out)I* do nothing *Ibuffer[in] = nextProduced;in = (in + 1) % BUFFER_SIZE;}
  20. 20. item nextConsumed;while (true) {while (in == out); II do nothingnextConsumed = buffer[out];out = (out + 1) % BUFFER_SIZE;I* consume the item in nextConsumed *I}