ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Linux] process
    programing/OS 2018. 7. 10. 10:38


    안녕하세요, Einere입니다.

    process와 thread에 대해 배우신 분들이 많을것 같습니다.

    오늘은 그 중에서, process에 대해 포스팅 하려고 합니다.



    process concept


    process : an instance of running program.

    프로세스는 실행중인 프로그램의 한 인스턴스입니다.

    우리가 자주 사용하는 인터넷 익스플로러, 크롬, 워드, 한글, 롤 등등 모두, 실행을 하게 된다면 프로세스가 생성됩니다.

    또한 프로세스는 각자 고유한 id를 가집니다.



    process in memory



    컴퓨터에서 프로그램을 실행시킨다면 disk에서 memory로 해당하는 data가 load됩니다.

    그리고 해당 process는 program counter, stack, data, text 등등의 data를 가지고 있습니다.



    process state


    프로세스는 총 5가지의 상태를 가질 수 있습니다.

    1. new : 지금 막 생성된 프로세스. scheduler에 의해 scheduling됩니다.

    2. running : 현재 프로세서에 의해 실행중인 프로세스.

    3. waiting : 어떤 이벤트의 발생을 기다리는 프로세스. waiting queue에 linked list형태로 존재하게 됩니다.

    4. ready : 프로세서에 의해 실행되기를 기다리는 프로세스. ready queue에 linked list형태로 존재하게 됩니다.

    5. terminated(zombie) : 모든 작업을 완료하고 종료된 프로세스.  프로세스가 죽는다면, 정상종료되었는지 등등의 최소한의 정보를 가지고 있는 zombie가 메모리상에 남아있게 됩니다.


    그리고 signal, exception, interrupt에 의해 프로세스의 상태는 변할 수 있습니다.



    process control block



    PCB : information associated with each process.

    PCB는 프로세스마다 가지고 있는, 자신에 대한 정보를 담고 있는 구조체입니다.

    PCB는 다음과 같은 정보를 가지고 있습니다.

    1. process state

    2. program counter

    3. CPU registers

    4. CPU scheduling information

    5. memory management information

    6. accounting information

    7. IO status information



    process scheduling

    1. multi programming : have some process running at all times, to maximize CPU utilization.

    CPU사용율을 극대화하기 위해서, 여러 프로세스를 동시에 실행하는 것.

    2. time sharing : To allow many users to share the computer simultaneously. Only a little CPU time is needed for each user. 

    많은 사용자가 컴퓨터를 동시에 사용하는 것.



    프로세스는 보통 위와 같이 round robin 방식으로 스케쥴링 됩니다. (scheduling method는 후술하겠습니다.)

    하나의 프로세스는 최대 time slice만큼만 실행되며,  time slice가 다되기 전에 특정 신호를 받으면 그에 따라 스케쥴링 됩니다.




    참고로 process switching은 위와 같은 과정을 가집니다.



    process scheduling queue


    job Q : set of all processes in the system.

    모든 프로세스에 대한 정보를 가지는 큐입니다.

    ready Q : set of all processes residing in main memory, ready to execute.

    프로세서에 의해 실행되기를 기다리는 프로세스들의 큐입니다.

    device Q : set of processes waiting for an I/O device

    IO를 기다리는 프로세스들의 큐입니다.

    waiting Q : set of process waiting for a resource (e.g., message queue, socket, semaphore, etc).

    특정 자원을 기다리는 프로세스들의 큐입니다.



    scheduler


    scheduler : select, for scheduling purposes, a process to migrate it the various scheduling queues through its lifetime.

    스케쥴러는 프로세스를 스케쥴링하는 녀석입니다.


    context switch


    context : represented in process control block. includes the value of the CPU registers, process state.

    PCB에 존재하며 프로세스에 대한 여러가지 정보를 가진 것입니다.

    context switch를 할 때, 현재 프로세스의 context를 저장하고, 실행할 프로세스의 context를 가져옵니다.
    그리고 cache와 TLB(translation lookup table)을 초기화하는데, 이때 overhead가 많이 들며, 초기화를 하므로 인해서 miss도 많이 발생하게 됩니다.
    따라서 process보다 가볍고 빠른 thread가 생겨나게 됩니다.


    process creation


    부모 프로세스는 자식 프로세스를 만들 수 있습니다.

    생성된 자식 프로세스는 부모 프로세스와 모든 자원을 공유합니다.

    그리고 부모 프로세스는 자식 프로세스가 종료되기를 기다립니다.



    process terminate


    프로세스 리소스(open file, allocated memory, IO buffer...)는 OS에 의해 제거됩니다.


    zombie process : When a process exits, it remains in zombie state until cleaned up by calling wait system of its parent. all resources except for process entry, exit status and resource usage information are removed. For example, open files, allocated memory are cleaned up.


    기본적으로 부모 프로세스는 자식 프로세스가 죽을 때 까지 기다립니다. 만약 자식 프로세스가 죽으면, 자식 프로세스의 리소스를 해제합니다.

    만약 자식보다 부모가 먼저 죽어버리면, init 프로세스가 해제합니다.



    process type


    1. independent process : cannot affect or be affected by the execution of another process. Any process that does not share data with any other process is independent.

    프로세스는 기본적으로 독립적이며, 서로 다른 프로세스에게 영향을 끼치지 않으며, 다른 프로세스의 자원을 침범할수도 없습니다.

    2. cooperating process : can affect or be affected by the execution of another process. Any process that share data with the other processes is a cooperating process.
    협력적 프로세스는 다른 프로세스에게 영향을 끼칠 수 있습니다. 다른 프로세스의 메모리 영역에 접근하여 자원을 사용할 수 있습니다.
    이러한 협력적 프로세스는 IPC를 통해 구현할 수 있습니다.
    협력적 프로세스를 사용하면 활용성이 높아지지만, 동기화나 자원사용에 있어서 주의를 기울여야 합니다.



    interprocess communication


    interprocess communication (IPC) : Mechanism for a process to communicate with its cooperating processes.

    위에서 언급한 바와 같이, 프로세스끼리 상호작용을 하기 위한 방법입니다.

    1. shared memory : A process can access the address space of the other processes with some system calls of shared memory.
    2. message system : Allow processes to communicate and to synchronize their actions without sharing the same address space.
    IPC를 구현하는 방법에는 위와 같이 두가지 방법이 있습니다.


    'programing > OS' 카테고리의 다른 글

    [OS] 공룡책 강의노트  (0) 2018.10.16
    [Linux] File System Implementation  (0) 2018.06.23
    [Linux] Disk Allocation Method  (0) 2018.06.16
    [Linux] Disk Scheduling  (0) 2018.06.16
    [Linux] Process & fork  (0) 2017.09.21

    댓글

Designed by black7375.