* 해당 게시물은 경북대학교 컴퓨터학부 강의초빙교수, 배준현 교수님의 강의를 보고 작성되었음을 미리 알려드립니다. ( 개인적인 공부를 정리한 글입니다. )
> 주니온 TV Youtube Channel. https://www.youtube.com/channel/UCOcPzXDWSrnaKXse9XOPiog
> 주니온 TV Inflearn page. https://www.inflearn.com/users/@joonion
[ ] Process Concept.
- A process is a program in execution.
- The memory layout of a process is divided in to multiple sections :
Text Section ( The executable code ), Data Section ( Global variables ),
Heap Section ( Memory that is dynamically allocated during program run time )
Stack Section ( temporary data storage when invoking functions + such as function parameters, return addresses, and local variables. )
- As a process executes, it changes its state.
New : the process is being created.
Running : Instructions are begin executed.
Waiting : the process is waiting for some event to occur. ( +such as an I/O completion or reception of a signal )
Ready : the process is waiting to be assigned to a processor.
Terminated : the process has finished execution.
Process는 위와 같이 5개의 Life cycle을 가지고 있고, 이것을 따라 OS는 Process를 관리한다.
Waiting은 모종의 이유로 CPU의 점유를 놓은 상태, Ready는 Waiting이 끝난 후 다시 CPU 자원을 할당 받기 위해 대기하는 상태.
[ ] How to manage the process in OS?
- PCB ( Process Control Block ) or TCB ( Task Control Block) 을 만들어 관리한다.
struct 안에 Process가 가져야 할 모든 정보를 저장해서 관리하는 것이 PCB.
Linux는 작업을 Task라 사용해서 TCB라고도 불린다.
- A PCB contains many pieces of information associated with a specific process:
Process state, ( Program Counter, CPU registers ) => 이 둘을 묶어 Context라 부른다.
CPU-scheduling information, Memory-management information, Accounting information, I/O status information.
[ ] The objective
The objective of multiprogramming is
- to have some process running at all times.
- so as to maximize CPU utilization.
The objective of time sharing is
- to switch a CPU core among processes so frequently
- that users can interact with each program while it is running.
시분할은 시간을 쪼개 여러 개의 Process을 조금씩 처리해 나가서 동시적으로 처리하는 것처럼 보이게 하는 것.
[ ] Scheduling Queues
- As processes enter the system, they are put into a ready queue, where they are ready and waiting to execute on a CPU's core.
- Processes that are waiting for a certain event to occur are placed in a wait queue.
[ ] Queueing Diagram
[ ] Context Switch
- The context of a process is represented in the PCB.
- The context switch is a task that
switches the CPU core to another process.
performs a state save of the current process and a state restore of a different process.
Multiprocessing은 OS에 의해서 Context switch로 이루어 진다.
[ ] Zombie and Orphan.
- Zombie process : a process that has terminated, but whose parent has not yet called wait().
- Orphan process : a process that has a parent process who did not invoke wait() and instead terminated.
[ ] In UNIX-like O/S,
- A new process is created by the fork() system call.
[ ] After a fork() system call,
- the parent can continue its execution; or if it has nothing else to do while the child runs, it can issue a wait() system call to move itself off the ready queue until the termination of the child.
fork는 context가 복제가 되므로 Child Process는 복제된 이후의 Code를 계속해서 실행하게 된다.
1번째 Process가 복제, 복제된 것과 부모 process는 다시 fork()을 Call하고 뒤의 코드가 복제되면서 반복되어 생성된다.
wait가 걸려있으므로, Child가 먼저 실행된다. Context가 전체 복제됨으로 전역변수 또한 복사가 되어 Parent 출력은 nums elements가 값의 변화가 없이 순서대로 출력된다.
[ ] Processes executing concurrently.
- Independent processes = A process is independent if it does not share data with any other processes.
- Cooperating processes = A process is cooperating if it can affect or be affected by the other processes.
Cleary, any processes that shares data with other processes is a cooperating process.
Cooperating processes 간의 메시지를 주고받을 때 발생하는 문제를 어떻게 해결할 것인가? = IPC
[★] IPC : Inter-Process Communication.
- Cooperating processes require an IPC mechanism that will allow them to exchange data that is, send data to and receive data from each other.
- Two fundamental models of IPC : shared memory, message passing.
[ ] Consider the Producer-Consumer Problem.
- to illustrate the concept of cooperating processes.
- a common paradigm for cooperating processes.
- A Producer produces info that is consumed by a consumer.
ex) a complier produces assembly code, and an assembler consumes it.
a web server produces an HTML file, and a browser consumes it.
- A solution using shared-memory :
To allow producer and consumer to run concurrently.
Let a buffer of items be available.
(Producer) can fill the buffer. (Consumer) can empty the buffer.
[★] The scheme of using shared-memory
- requires that these processes share a region of memory and that the code for accessing and manipulation the shared memory - be written explicitly by the application programmer.
P와 C 가 1 by 1 매칭이 되면 괜찮겠지만, 만약 P가 N이고 C가 M일 경우 어떻게 Shared buffer를 구성할 것인가?
이는 전적으로 프로그래머의 몫이다.
[★] Message-Passing
- O/S provides the means for cooperating processes to communicate with each other via a message-passing facility.
Message만 던지고 나머지 처리는 OS에게 넘긴다.
- The properties of communication links in this scheme( Direct )
반드시 누구에게 줄 것인지, 누구에게 받을 것인지 명시해 준다. > Links are established automatically.
There exists exactly one link between each pair of processes.
- The properties of communication links in this scheme( Indirect )
the massages are sent to and received from mailboxes, or ports.
두 명의 member가 공유할 수 있는 port가 있을 때, 더 많은 process 도 가능하다.
A number of different links may exist, between each pair of processes with each link corresponding to one port.
- Different design options for implementation:
blocking or non-blocking : synchronous or asynchronous.
Blocking send : the sender is blocked until the message is received. (Receiver 도 마찬가지)
Non-blocking send : the sender is sends the message and continue. (Receiver 도 마찬가지)
[ ] Examples of IPC Systems
- Shared Memory: POSIX Shared Memory. ( POSIX : Portable Operating System Interface (for UNIX)
OS의 표준화를 꿰차기 위해 만듦.
- Message passing : Pipes ( One of the earliest IPC mechanisms on UNIX systems.)
[ ] POSIX shared memory.
- is organized using memory-mapped files, which associate the region of shared memory with a file.
UNIX에서 구현한다면 일일이 Open하고 Write하고 Read하고 Close해주고 등 할 것이 많다.
[ ] Pipes
- Pipes were one of the first IPC mechanism in early UNIX systems.
- A pipe acts as a conduit allowing two processes to communicate.
*conduit n. 전달자[기관, 정부], 도관(액체나 기체를 통하게 하는)
[ ] Four issue of pipe implementation.
- Does the pipe allow unidirectional or bidirectional communication?
uni(한쪽으로만 전송) VS bi (양쪽 모두 전송)
- In the case of two-way comm., is it half-duplex or full-duplex?
둘이 왔다 갔다 할 수 있는지, uni pipe를 2개 만들면 간단한 문제.
- Must a relationship exist between the communicating process?
+ such as parent-child. / 사실 주고 받고라서 그럴 필요는 없지만 pipe를 사용하는 편의상 가진다.
- Can the pipes communicate over a network?
이때는 pipe라 안 부르고, Socket이라 부른다.
[ ] Ordinary Pipes
- allow two processes to communicate in producer-consumer fashion.
the producer writes to one end of the pipe. (write end)
the consumer reads from the other end (read end)
- unidirectional : only one-way communication is possible.
- two-way communication? use two pipes!
[ ] Two other strategies in client-server system.
- Sockets are defined endpoints for communication.
데이터를 주고 받을 때, 한쪽은 32bit, 한쪽은 64bit 일 경우 둘의 통신에 문제가 발생한다. 일일이 용량별로 보내는 데이터를 결정했다. 그래서 이것을 해결하기 위해 RPCs가 등장했다.
- RPCs ( Remote Procedure Calls )
abstracts procedure calls between processes on networked systems.
[ ] Socket
- A socket is identified by an IP address concatenated with a port number.
[ ] Java provides
- Socket class : connection -oriented(TCP)
- DatagramSocket : connectionless(UDP)
- MulticastSocket : multiple recipients.
Java 제공하는
[ ] RPC + java에서는 RMI (Remote Method Invocattion) 이라 부른다.
- one of the most common forms of remote service.
- designed as a way to abstract the procedure-call mechanism for use between systems with network connections.
[ ] The RPC System
- hides the details that allow communication to take place by providing a stub on the client side.
IPC 의 확장 개념 > RPC는 Network 간에 있는 두 PC끼리 데이터를 주고받는다.
'Computing > Operating System' 카테고리의 다른 글
08 > CPU scheduling (0) | 2021.11.15 |
---|---|
06 - 07 > Thread [쓰레드, 멀티 쓰레딩] (0) | 2021.11.07 |
01 - 02 Intro [운영체제란?, 운영체제 개념과 구조] (0) | 2021.11.07 |
[GNU] 정리. (0) | 2021.10.13 |
Memory Leak, Cache Hit&Miss (0) | 2021.10.13 |