3. UNIX Process, I/O and Credentials#


../_images/Processes.001.png
../_images/syscalls.png

3.1. Processes, Files and Streams#

3.1.1. What is a process in more detail and what can it do#

  • a running program

    • a process can launch other processes

      • bash is implemented to start commands as processes (when needed)

      • passes command line arguments and environment variables – a set of key value pairs Eg.

        • x=cool

        • HOME=/home/jovyan


../_images/Processes.002.png
../_images/Processes.003.png
../_images/Processes.004.png
../_images/Processes.005.png
../_images/Processes.006.png

3.1.2. Processes, Files and channel/stream model of I/O#

3.1.2.1. Files and Kernel objects#

  • read, write

  • everything is a file


../_images/Processes.007.png
../_images/Processes.008.png
../_images/Processes.009.png
../_images/Processes.010.png

3.1.3. Streams: Processes and Files#

  • open : attach a file as a stream

  • file descriptors/handles : stream

    • read and write bytes to a stream

    • close

    • dup

  • standard input, standard output, standard error


../_images/Processes.011.png
../_images/Processes.012.png
../_images/Processes.013.png
../_images/Processes.014.png
../_images/Processes.015.png
../_images/Processes.016.png
../_images/Processes.017.png
../_images/Processes.018.png

3.1.4. Shell Syntax:#

  • echo 'Hello world' > hello

  • cat hello

  • cat < ./hello


../_images/Processes.019.png
../_images/Processes.020.png

3.1.5. We now can understand what a pipe is#

  • pipe file object

    • Process 1 stdout into pipe and Process 2 stdin from pipe

3.1.6. Shell Syntax:#

  • ls -1 | wc -l

  • ls -1 | grep '^l*' | wc -l

  • mknod mypipe p and mkfifo mypipe


../_images/Processes.021.png
../_images/Processes.022.png
../_images/Processes.023.png
../_images/Processes.024.png
../_images/Processes.025.png
../_images/Processes.026.png
../_images/Processes.027.png

3.2. Process management#

  • ps - look at all processes

  • The shell and its children

    • & : foreground and background

    • ctrl-z

    • jobs

  • so we know how to start process, list them how about stopping

    • kill

    • signals

      • ctrl-c

    • or without prejudice


../_images/Processes.028.png
../_images/Processes.029.png
../_images/Processes.030.png
../_images/Processes.031.png
../_images/Processes.032.png
../_images/Processes.033.png
../_images/Processes.034.png
../_images/Processes.035.png
../_images/Processes.036.png

3.3. Credentials and file permissions#

  • Process have id’s associated with them

    • a single user id : id

      • a single number that maps to a string user name (/etc/passwd)

    • set of group ids

      • user has a primary group but can be in many secondary groups

      • each has a number that maps to a name (/etc/group)

      • each group can have many users

    • ps auxgww

      • process’s inherit their ids from their parent


../_images/Processes.037.png
../_images/Processes.038.png
../_images/Processes.039.png
../_images/Processes.040.png
../_images/Processes.041.png
  • Files have id’s and permissions ls -l, chmod, chown, and chgrp

    • user, group, other -> read, write, execute

    • kernel ensures that process id’s and requested operations match permissions


../_images/Processes.042.png
../_images/Processes.043.png
../_images/Processes.044.png
../_images/Processes.045.png
../_images/Processes.046.png
../_images/Processes.047.png
../_images/Processes.048.png
../_images/Processes.049.png
../_images/Processes.050.png