Presentation is loading. Please wait.

Presentation is loading. Please wait.

Processes Chapter 3 These slides include text, figures, and information from Operating Systems Concepts, by Silberschatz, Galvin, and Gagne. They also.

Similar presentations


Presentation on theme: "Processes Chapter 3 These slides include text, figures, and information from Operating Systems Concepts, by Silberschatz, Galvin, and Gagne. They also."— Presentation transcript:

1 Processes Chapter 3 These slides include text, figures, and information from Operating Systems Concepts, by Silberschatz, Galvin, and Gagne. They also include material from the slides that accompany that textbook and from slides made by Dr. Roger deBry.

2 Process: a program in execution
Figure 3.1 Process in memory Figure 3.3 Process control block (PCB)

3 Process state Figure 3.2 Diagram of process state

4 Linux PCB: task_struct
pid t_pid; /* process identifier */ long state; /* state of the process */ unsigned int time_slice /* scheduling information */ struct task_struct *parent; /* this process’s parent */ struct list_head children; /* this process’s children */ struct files_struct *files; /* list of open files */ struct mm_struct *mm; /* address space of this process */ See page 110 of Silberschatz or

5 Process scheduling Long-term scheduler:
Decides which processes to load into memory for execution Controls the degree of multiprogramming Tries to select a good mix of I/O-bound and CPU-bound processes Why is the degree of multiprogramming important? What are examples of I/O-bound and CPU-bound processes? Why is it important to get a good mix? CPU scheduler: Decides which process in the ready queue will run next

6 Scheduling queues Ready queue Device queues
Job queue: all processes in the system Figure 3.5 The ready queue and various I/O device queues

7 Context switch Figure 3.4 Diagram showing CPU switch from process to process

8 Process creation Parent and child processes (and siblings) pid
Figure 3.8 A tree of processes on a typical Linux system

9 Process creation Address space UNIX examples Child duplicate of parent
Child has a program loaded into it UNIX examples fork() system call creates new process exec() system call used after a fork() to replace the process’ memory space with a new program

10 C program forking separate process

11 Process termination Process executes last statement and then asks the operating system to delete it using the exit() system call. Returns status data from child to parent (via wait()) Process’ resources are deallocated by operating system Parent may terminate the execution of children processes using the abort() system call. Some reasons for doing so: Child has exceeded allocated resources Task assigned to child is no longer required The parent is exiting and the operating systems does not allow a child to continue if its parent terminates

12 Process termination Some operating systems do not allow child to exists if its parent has terminated. If a process terminates, then all its children must also be terminated. cascading termination. All children, grandchildren, etc. are terminated. The termination is initiated by the operating system. The parent process may wait for termination of a child process by using the wait()system call. The call returns status information and the pid of the terminated process pid = wait(&status); If no parent waiting (did not invoke wait()) process is a zombie If parent terminated without invoking wait , process is an orphan

13 Interprocess communication
Message passing Shared memory

14 Which is best? Message passing Shared memory
Don’t have to avoid conflicts Easier to implement in distributed system Shared memory Can be faster: no system calls after initial set-up Can have cache coherency issues in systems with more than one processing core Which is best?

15 Producer item next_produced; while (true) { /* produce an item in next produced */ while (((in + 1) % BUFFER_SIZE) == out) ; /* do nothing */ buffer[in] = next_produced; in = (in + 1) % BUFFER_SIZE; } Consumer item next_consumed; while (true) { while (in == out) ; /* do nothing */ next_consumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; /* consume the item in next consumed */ } What happens when the producer and consumer try to access the buffer at the same time?

16 Producer Consumer message next_consumed; } message next_produced;
while (true) { /* produce an item in next produced */ send(next_produced); } Consumer message next_consumed; while (true) { receive(next_consumed); /* consume the item in next consumed */ }

17 Message passing If processes P and Q wish to communicate, they need to: Establish a communication link between them Exchange messages via send/receive Implementation issues: How are links established? Can a link be associated with more than two processes? How many links can there be between every pair of communicating processes? What is the capacity of a link? Is the size of a message that the link can accommodate fixed or variable? Is a link unidirectional or bi-directional?


Download ppt "Processes Chapter 3 These slides include text, figures, and information from Operating Systems Concepts, by Silberschatz, Galvin, and Gagne. They also."

Similar presentations


Ads by Google