## processes #### csci 2410 | fall 2023 #### Prof. Sibin Mohan

tackling complexity

  • modern computers → 100s of programs
  • programs can interfere with each other
  • complex!




abstractions!

### isolation
### isolation - one program **cannot** interfere with another
### isolation - one program **cannot** interfere with another - core provision of modern OSes and architectures

process

process

- process ID pid

- memory acessible only to process

  [code, global data, stack, heap]

- integer descriptors that identify resources

  [file system, networking, communication]

- current working directory pwd

- owner sibin

process

- parent → creator, responsible for it

- arguments passed from command line

- environment variables → system config information

### Unix Philosophy
### Unix Philosophy - programs should be **simple**
### Unix Philosophy - programs should be **simple** - **should not** be large monolithic pieces of code
### Unix Philosophy - programs should be **simple** - **should not** be large monolithic pieces of code - "doing one thing well" - e.g., `ls`, `ps`, `pwd`, etc.
### Unix Philosophy - programs should be **simple** - **should not** be large monolithic pieces of code - "doing one thing well" - e.g., `ls`, `ps`, `pwd`, etc. - **pipelines** of processes
### Unix Philosophy - programs should be **simple** - **should not** be large monolithic pieces of code - "doing one thing well" - e.g., `ls`, `ps`, `pwd`, etc. - **pipelines** of processes - `$ ps aux | grep sibin`
### `fork()`
### `fork()` Create a new, child, process
##### process creation/termination/coordination API --- ##### process creation/termination/coordination API |name| action | |------|-------| --- ##### process creation/termination/coordination API |name| action | |------|-------| |`fork` | create process | --- ##### process creation/termination/coordination API |name| action | |------|-------| |`fork` | create process | |`getpid` | get ID of process | --- ##### process creation/termination/coordination API |name| action | |------|-------| |`fork` | create process | |`getpid` | get ID of process | |`getppid` | get ID of parent | --- ##### process creation/termination/coordination API |name| action | |------|-------| |`fork` | create process | |`getpid` | get ID of process | |`getppid` | get ID of parent | |`exit` | terminate a process | --- ##### process creation/termination/coordination API |name| action | |------|-------| |`fork` | create process | |`getpid` | get ID of process | |`getppid` | get ID of parent | |`exit` | terminate a process | |`wait` | parent waiting for child to exit | --- ##### process creation/termination/coordination API |name| action | |------|-------| |`fork` | create process | |`getpid` | get ID of process | |`getppid` | get ID of parent | |`exit` | terminate a process | |`wait` | parent waiting for child to exit | |`exec` | new program from _current process_ | ||
### process vs program
### process vs program - program → **compiled** version of code - process → program **executing** in memory