0%

NTHU-Operating System Chap3 Process Concept

Process Concept

Process in Memory

Threads

Process State

Diagram of Process State

Process Control Block (PCB)

Context Switch


Review Slides(1)

Process Scheduling

Process Scheduling Queues

Process Scheduling Diagram

Schedulers

对一个进程来说有虚拟地址空间,由于内存空间有限,对于那些不常用的一般情况下会放到disk上,需要的时候再swap到memory,这就是所谓的Medium-term

Long-Term Scheduler

Short-Term Scheduler

Medium-Term Scheduler

Operations on Processes

Tree of Processes

Processes Creation

UNIX/Linux Process Creation


UNIX/Linux Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>
int main( )
{
int A;
/* fork another process */
A = fork( );
if (A == 0) { /* child process */
printf("this is from child process\n");
execlp("/bin/ls", "ls", NULL);
} else { /* parent process */
printf("this is from parent process\n");
int status;
int pid = wait(&status);
printf("Child %d completes", pid);
}
printf("process ends %d\n", A);

return 0;
}

执行结果:

1
2
3
4
5
6
7
8
#include <stdio.h>
#include <unistd.h>
int main() {
for (int i = 0; i < 3; i++){
fork();
}
return 0;
}

Process Termination

Interprocess Communication (IPC)

Communication Methods


Shared Memory

Consumer & Producer Problem

Shared-Memory Solution

Message Passing


Direct Communication


Indirect communication


Synchronization

Socket


Remote Procedure Calls: RPC


求大佬赏个饭