[OSTEP] 3. Process API

ch5: 프로세스를 다루는 API들을 알아보자

Table Of Contents

CH5: Interlude: Process API

discuss process creation in UNIX systems

1. The fork() System Call

Example

  1. process(PID 29146) prints out a hello world message
  2. process(PID 29146) calls fork() system call
    • The odd part:
      • the process that is created is an (almost) exact copy of the calling process
      • to the OS, it looks like there are two copies of the program p1 running, and both are about to return from the fork() system call.
      • the child doesn't start running at main(), rather, it just comes into like as if it had called fork() itself
    • che chilid isn't ans exact copy
      • the value it returns to the caller of fork() is different:
        • the parent receives the PID of the child
        • the child receives a return code of zero

2. The wait() System Call

make parent to wait for a child process to finish what it has been doing.

Example

3. The exec() System Call

run a program that is different from the calling program

Example

4. Why?

the separation of fork() and exec()

redirection

prompt> wc p3.c > newfile.txt

pipe

5. Process Control

There are a lot of other interfaces for interacting with processes in UNIX systems