quartz/content/notes/17-processes-communication.md
2022-10-22 11:28:04 +13:00

2.9 KiB

title aliases tags sr-due sr-interval sr-ease
17-processes-communication
cosc204
lecture
2022-10-28 6 230

process tree example

cooperating processes

defn: coop process - execution of one process can affect the execution of another. e.e.g, processes for aprallel computing, threads for multithreading.

defn: independent process - one does not affect the other and they do not communicate etc

creating a child process

A child process is creating from a parent using fork.

fork returns a value. 0 for the parent, and the id of the child for the child

everything the same as the parent except the child has a differnent process ID. e.g., when they start they the same heap location etc. but as the child runs it may change.

if you kill the parent before the child the child becomes an orhpan process if yo ukill the child while the parent is waiting for the child the parent becomes a zombie (defunct) process. -- but only if the parent doesn't wait for the child.

the child process can also call exexlp (load program) which erases the copy of the parent (itself not the parent)

  • when initally forked the child and parent share the same space
  • when the child calls execlp then the child will fully copy the program to a new memory location so it doesn't overwrite the parent

communcation between parent and child

process create a chld process to do a task. but they need to communicate

after a process calls a chld process. it can execute a wait system call.

this moves a process off the ready queue, untill the chld process has terminated when the child process has terminated, it can return its status to the parent.

process termination

automatically executes exit after the last statement.

  • may return status to parent who is waiting
  • all rsouces are dallocated by the OS

they can also die more violently

  • kill command
  • you can only processes you 'own'
  • Orphan process: a process whose parent terminated (inherited by init)
  • Zombie process: one which terminated, but its live parent process is not WAITING for it. Since no process is receiving its exit status, it stays in the process table

signal and pipe for inter process communication

signal

communication between OS kernel and processes and between processes

  • process can install a handler (function) for a signal using the system call signaction() except for SIGKILL
  • The default action for a signal is usually to kill/terminate the process if a handler is not installed.
  • Other actions are ignore, core (dump a large file for debugging), stop(stop the process), and continue. The last two actions are used by debuggers like gdb to debug a program.

partial list of signals

pipe

connect process output and another process input.

uni-directional channel

file descriptors

  • 0 - stdin
  • 1 - stdout
  • 2 - sterr

you can make file descriptors point to the same file using dup/dup2/dup3