OS_Chapter_3.3

ssonjh·2021년 4월 9일
0

OS

목록 보기
17/17

👀 Operations on Processes

  • The Processes in most system can execute concurrently, they may be created and deleted dynamically.

  • Thus, system must provide mechanism for
    • Process Creation
    • Process Termination

Summary

  • Process들은 병렬로 실행될 수 있으며, 동시에 동적으로 생성/제거된다.
  • system은 반드시 Process의 생성/제거에 대한 mechanism을 제공할 수 있어야 한다.

📕 Process Creation

  • Parent process create children processes, which, in turn create other processes, forming a tree of processes

Process Identifier (PID)

  • Generally, process identified and managed via a process identifier (pid)
  • Pid is unique value for each process

  • Resource sharing options
    • Parent and children share all resources
    • Children share subset of parent’s resources
    • Parent and child share no process

  • Execution options
    • Parent and children execute concurrently
    • Parent waits until children terminate

  • Systemd
    • root parent process for all user processes

Summary

  • 상위 process는 하위 process를 생성하고, 이는 차례대로 다른 process를 생성하여 결과적으로 프로세스 tree를 형성하게 된다.

프로세스 식별자 (PID)

  • 일반적으로 process는 pid로 불리는 process 식별자를 통해 process들을 식별하고 관리한다.
  • PID는 각 process마다 고유한 값을 가지고 있다.

자원 공유

  • process는 하위 process를 만들고, 하위 process 역시 상위 process처럼 resouce가 필요하다. 하위 process는 resource를 얻기 위해 2가지 방법이 있는데, OS로부터 직접 얻는 방법과 상위 process에서 공유해 주는 방법이 있다. 그러나 주로 상위 process에서 공유해 주는데, 너무 많은 하위 process를 만들어 system이 과부하가 일어나는 것을 방지하기 위함이다.

실행

  • 상위와 하위 process는 동시에 실행되어야 한다.
  • 상위 process는 하위 process가 끝날 때 까지 기다려야 한다.

Systemd

  • linux에서 최종적으로 모든 process들을 관리하는 init 시스템을 말한다.

two possible ways according to address space of the new process:

• Child is a duplicate of parent
• Child has a new program loaded into it

  • Unix example
    • fork() system call creates new process
    • exec() system call used after a fork() to replace the process’ memory space with a new program
    • Parent process calls wait() for the child to terminate

  • C Program Forking Separate Process

  • Windows API Forking Separate Process

Summary

새로운 process의 주소

  • 하위 process는 상위 프로세스와 중복될 수 있다. 예를 들어, 상위 process는 상위 process와 동일한 데이터 및 프로그램을 가진다.
  • 하위 process는 새 program을 안에 load할 수 있다.
  • 상위 process는 하위 process가 끝날 때 까지 wait()를 실행한다. (대기 상태)

Unix example

  • 'fork()'라는 system call이 새로운 process를 생성한다.
  • 'exec()'라는 system call이 process의 memory공간과 새 program을 대신하기 위해서 fork() 다음에 실행된다.

fork()

PID 가 완전히 다른 또 하나의 process가 생기는 것

exec ()

반면 exec()실행의 결과로 생성되는 새로운 process는 없고, exec()를 호출한 process의 PID가 그대로 새로운 process에 적용이 되며, exec()를 호출한 process는 새로운 process에 의해 덮어 쓰여지게 된다.

📙 Process Termination

  • Process executes last statement and then asks the operating
    system to delete it using the exit() system call.

  • Returns status data from child to parent (via wait())

  • Process’ resources are deallocated by operating system

  • Parent may terminate the execution of children processes using the abort() system call. Some reasons for doing so:
    • Child has exceeded allocated resources
    • Task assigned to child is no longer required
    • Usually, it can be invoked only by parents

  • The parent is exiting and the operating systems does not allow a child to continue if its parent terminates -> All children terminated (cascading termination)

  • The parent process may wait for termination of a child process by using the wait() system call. The call returns status information and the pid of the terminated process pid = wait(&status);

zombie processer

  • If no parent waiting (did not invoke wait()) process is a zombie

Orphan processer

  • If parent terminated without invoking wait , process is an orphan
    • root process is assigned as the parent process

Summary

  • Process는 마지막 명령를 실행한 후 OS에 'exit()'라는 system call을 사용해 삭제를 요청한다.
  • 하위 process에서 상위 process로 'wait()'를 통해 현재 data를 return한다.
  • process의 resource가 OS에 의해 할당이 해제된다.
  • 상위 process는 다음과 같은 상황에서 실행중인 하위 process를 'abort()'를 통해 종료시킬 수 있다.
    • 하위 process가 할당된 resource를 넘겼을 때
    • 하위 process에 할당된 작업이 더 이상 필요하지 않을 때
    • 보통, 상위 process에서만 종료를 시킬 수 있다.
  • 상위 process가 끝나면 OS는 하위 process가 계속 실행되도록 하지 않는다. -> 모든 하위 process가 종료된다. (계단식 종료, cascading termination)
  • 상위 process는 'wait()'를 통해 하위 process의 종료를 기다릴 수 있고, 해당 call은 상태 정보와 종료된 process의 pid를 반환한다. pid = wait(&status);

zombie process

  • process가 종료되었음에도 불구하고 memory에서 process의 정보가 남아있는 상태.
  • 상위 process가 os에 하위 process의 종료에 대한 요청을 해야하는데, 요청한 값이 들어오지 않는 상태.

Orphan process

  • 상위 process가 하위 process보다 먼저 종료되는 경우
  • OS가 확인하여 상위 process의 init을 1로 (root process)로 설정한다.

📒 Android Process Importance Hierarchy

  • Mobile operating systems often have to terminate processes to reclaim system resources such as memory. From most to least important:
    • Foreground process
    • Visible process (still can be seen in foreground process)
    • Service process (running background but apparent to user)
    • Background process (not apparent to user)
    • Empty process (no active components)
  • Android will begin terminating processes that are least important.

Summary

  • 모바일 OS는 memory와 같은 시스템 resource를 회수하기 위해 process를 종료해야 하는 경우가 많다. 가장 중요한 것 -> 덜 중요한 것 순:
    • Foreground process
    • Visible process
    • Service process
    • Background process
    • Empty process
  • 덜 중요한 것부터 process를 종료한다.

Multiprocess Architecture – Chrome Browser

  • Many web browsers ran as single process (some still do)
    • If one web site causes trouble, entire browser can hang or crash
  • Google Chrome Browser is multiprocess with 3 different
    types of processes:
    • Browser process manages user interface, disk and network I/O
    • Renderer process renders web pages, deals with HTML,
    Javascript. A new renderer created for each website opened
    • Plug-in process for each type of plug-in
  • 많은 browser들은 single process이지만, chrome은 3가지의 다른 multiprocess가 있다.
  1. Browser prosess
  2. Renderer process
  3. Plug-in process

0개의 댓글