본문 바로가기

Domain/시스템 프로그래밍

5. Task Programming

Task-Related System Call

 

Task creation

 fork()

  • Make a new task (same memory image of parent task)
  • Split the flow control into two (시스템적 관점)
  • Two return value (프로그램 관점) - parent : 자식의 pid / child : 0

 

child process에서 지역, 전역 변수 값을 증가시켜도 parent process의 값은 변하지 않는다.

 

fork의 시스템적 관점

 

Task Execution

 execve

  Replace the current task's meemory image with new binary

The role of loader

child process가 hello 바이너리 파일로 교체되어 "Child I'm here 문장이 출력되지 않았다.

 

execve의 시스템적 관점

 

Shell

 Command Interpreter

 

기본 기능

  • Display prompt, input parsing
  • Internal command : perform in shell
  • External command : do fork() and execve() at child task

심화 기능

  • Background processing : wait()을 사용하지 않는다. shell과 command가 동시에 수행됨.
  • Redirection : 표준 입/출력을 다른 파일로 교체한다. execve()전에 dup2()를 사용한다.
  • Pipe : IPC(Inter Process Communication), 두 태스크 간의 통신. execve()전에 pipe()와 dup2()를 사용하여 표준입/출력을 fd[0]/[1]로 교체한다.

 

Pipe

 

 

Race Condition(경쟁 상태)

경쟁 상태의 조건은 자원 공유와 time sharing system이다.

글자가 뒤죽박죽 출력된다.

 

Thread

Thread의 특징

  • data영역을 공유한다는 이점이 있다.
  • 속도 측면에서 유리하다.
  • 결함 발생시에 문제가 크다.

Process의 특징

  • 각 process는 모두 독립적이다.
  • 결함 발생시에 문제가 있는 process만 영향이 있다.

 

 

fork vs pthread_create Example

'Domain > 시스템 프로그래밍' 카테고리의 다른 글

3. File Programming  (0) 2020.03.14
4. Process Structure  (0) 2020.03.14
6. IA Assembly Programming  (0) 2020.03.14
7. IA : History & Features  (0) 2020.03.14
8. Optimization  (0) 2020.03.14