Computing/Operating System

03 - 05 > Process [프로세스의 이해, 생성, 통신]

i독 2021. 11. 7. 16:23

* 해당 게시물은 경북대학교 컴퓨터학부 강의초빙교수, 배준현 교수님의 강의를 보고 작성되었음을 미리 알려드립니다. ( 개인적인 공부를 정리한 글입니다. )

 

> 주니온 TV Youtube Channel. https://www.youtube.com/channel/UCOcPzXDWSrnaKXse9XOPiog

 

주니온TV 아무거나연구소

TMI Lab. 아무거나 연구소의 유튜브 TMI 지식나눔 채널 컴퓨팅 사고력을 키워 주고 코딩 지능을 길러 주는 자세히 보면 유익한 코딩 채널 주니온TV@Youtube 주니온 박사: 현) 경북대학교 컴퓨터학부 초

www.youtube.com

> 주니온 TV Inflearn page. https://www.inflearn.com/users/@joonion

 

주니온님의 소개 - 인프런 | 온라인 강의 플랫폼

인프런 지식공유자 주니온님의 소개 페이지 입니다. - 지식공유자 소개 | 인프런...

www.inflearn.com


[  ] 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. )

Figure 3.1 Layout of a process in memory.

 

- 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 자원을 할당 받기 위해 대기하는 상태.

 

Figure 3.2 Diagram of process state.

 

 

[  ] 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.

 

Figure 3.3 Process control block(PCB).

 

[  ] 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.

Figure 3.4 The ready queue and wait queues.

 

[  ] Queueing Diagram

Figure 3.5 Queueing-diagram representation of process scheduling.

 

[  ] 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.

Figure 3.6 Diagram showing context switch from process to 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.

 

Child PID 는  0 을   가지므로  wait() 을   실행하지   않는다 .  조건   아래의   문장은  Child 가   먼저   실행   후  Parent Process  가   실행된다 .

fork context 복제가 되므로 Child Process 복제된 이후의 Code 계속해서 실행하게 된다.

 

Process 는  2^4 = 16 개가   생성된다 .

1번째 Process 복제, 복제된 것과 부모 process 다시 fork() Call하고 뒤의 코드가 복제되면서 반복되어 생성된다.

 

 

CHILD : 0,1,4,9,16 / Parent : 0,1,2,3,4

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.

Figure 3.11 Communication models. (a) Shared memory, and (b) 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!

 

Figure 3.20 File descriptors for an ordinary pipe.

 

 

[  ] 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