OS-3-Process concept
# Outline:
1. process concept
2. process scheduling
3. operations on processes
4. Inter-process communication
1. process concept:
process = a program in execution
Process state:
- new: The process is being created
- running: Instructions are being executed
- waiting: The process is waiting for some event to occur (I/O request)
- ready : The process is waiting to be assigned to a processor
- terminated : The process
PCB(process control block)
- 프로세스의 모든 정보를 담고 있는 자료구조( process state, program counter, cpu registers, cpu scheduling information, memory-management information , accounting information , i/0 status information 등등)
- context switch가 발생하면:
- 다른 프로세스로 전환될때 실행중이던 process의 모든 정보인 snapshot를 PCB에 저장해놓는다.
- 나중에 이 프로세스의 상태가 ready->running 으로 바뀌어도 PCB의 값을 보고 다시 실행을 이어나갈수있다.
2. Process scheduling:
- Scheduling queue: Process들을 담을 공간
1. Job queue: 모든 프로세스들의 집합
2. Ready queue: State가 Ready인 프로세스들의 집합
3. Device queue: I/O 디바이스를 기다리는 프로세스의 집합
프로세스들은 다양한 큐 사이를 이동한다.
- Scheduler:
- Long-term scheduler(Job scheduler):
메모리를 어떻게 할당할지를 결정
어떤 프로세스를 Ready queue에 넣을지 결정
- Short-term scheduler(CPU scheduler):
빠르게 context switching을 해준다.
Ready queue에서 프로세스를 선택
concurrently처럼 보이게 해준다.
- Medium-term scheduler:
Swapping을 담당한다.
Context switch:
1. Job queue: 모든 프로세스들의 집합
2. Ready queue: State가 Ready인 프로세스들의 집합
3. Device queue: I/O 디바이스를 기다리는 프로세스의 집합
프로세스들은 다양한 큐 사이를 이동한다.
- Long-term scheduler(Job scheduler):
메모리를 어떻게 할당할지를 결정
어떤 프로세스를 Ready queue에 넣을지 결정 - Short-term scheduler(CPU scheduler):
빠르게 context switching을 해준다.
Ready queue에서 프로세스를 선택
concurrently처럼 보이게 해준다. - Medium-term scheduler:
Swapping을 담당한다.
When CPU switches to another process, the system must
save the state of the old process and
load the saved state for the new process
Context-switch time is a big overhead;
3. Operation on processes
Process creation(fork)
Process termination(exit)
Operation on process
-
Resoource sharing options
child share subset of parent's resources
-
Execution options
Parent and child execute concurrently
Parent waits until child terminates (wait() 함수를 이용하여)
-
Address space
child duplicates parent's address space
child has a program loaded into it(exec() 함수를 이용하여)
Fork system call
- resource sharing:
- parent and children share files
- CPU time or memory(address space) are not shared (부모와자식프로세스는 별도의 프로세스이므로)
- Execution
- parent and children execute concurrently
- Address space
- Child Duplicate parent address space
- Call once, return twice:
- fork() return value의 값이 parent(=pid of child)와child(=0)에 따라 다르다.
- Every process has the same program!
exec system call is used to load a new program
- Reaping child processes(부모가 자식을 거둔다)
parent waits for its children to terminate
zombie process
자식 프로세스가 exit()하였는데 부모 프로세스가 wait() 하지않아 자식 프로세스가 zombie 상태가 되는것.
Process termination
-
exit: 마지막문장에서 실행되고 OS에게 자발적으로 삭제해달라고 요청한다.
-
abort: 부모가 자식 프로세스를 종료시키는 것.
위 그림에서 1번은 orpahn process가 발생한것이고, 2번은 cascading termination이 발생한것이다.
4. Inter-process communication(IPC)
-
Independent process cannot affect or be affected by the execution of another process
-
Cooperationg process can affect or be affected by the execution of another process.-> Process 간 communication이 필요하다.
-
장점:
- information sharing(ex:file)
- computation speed-up
- modularity
- convinience
IPC:
- Message passing
- Shared Memory
위 두가지 방법은 os의 도움이 있어야 한다.
- Producer-Consumer problem using a programmed shared-memory
- producer process produces information
- consumer consumes informathion
- Must be synchronized
Spinlock:
버퍼가 비어있거나, 가득차있을때 발생하는 것.
while(); 루프를 계속돌고 있는 상황
Shared memory:
-
shmget: 프로세스가 share memory를 만든다.
-
shmat: 프로세스가 자신의 address space를 shared memory에 붙인다.
Message-passing:
- IPC facility provides two operations:
- send(message)
- receive(message) - If P and Q communicate:
- establish Communication link (maibox) between them
- exchange messages via send/receive
Establishing links:
-
Direct communication
- process must name each other explicitly (= "hard-coding") -> 이름이 바뀌면 recompile 해야한다.
- send(P,message) - send a message to process P
- receive(Q,message) - receive a message from process Q
-
Indirect communication:
- Messages are directed and received from mailboxes
- each mailbox has a unique id
- processes can communicate only if thy share a mailbox
Direct communication vs Indirect communication:
-
Direct communication(pipe):
- Links are established automatically
- usually bi-directional
- Between each pair there exists exactly one link
- shortcoming: can we know the name in advance? -
Indirect communication
- link established only if processes share a common mailbox
- A link may be associated with many processes
- Each pair of processes may share several communication links
- link may be unidirectional or bi-directional
-
A link may be associated with many processes.
-
Each pair of processes may share several commuication links.
Indirect communication operations:
- create a new mailbox.
- send and receive messages through mailbox.
- destroy a mailbox.
who gets the message (if p2,p3 tries)?
- allow a link to be assocaited with at most two processes.
- Broadcasting
- allow only one process to receive a message.
- Allow the sending process to select the receiver.
Mailbox synchronization:
-
Message passing may be either blocking or non-blocking.
-
Blocking is considered Synchronous.
-
Non-blocking is considered Asynchronous.
OS는 Primitive만 제공해주고, 옵션은 프로그래머가 선택한다.
IPC comparsion
Message VS Shared memory:
- Message-passing:
useful for inter-computer communication , exchanging smaller amounts of data and implemented using system calls so it is time-consuming. - Shared memory:
producer-consumer system -> synchronization을 위한 spinlock이 개발되었다.
Author And Source
이 문제에 관하여(OS-3-Process concept), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@yyong3519/OS-3Process-concept저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)