Based on Chapter 7 and Section 8.3 of [Hai19]
(Usage hints for this presentation)
Computer Structures and Operating Systems 2023
Dr. Jens Lechtenbörger (License Information)
/proc
(or
alternatives for your OS), build pipelines, redirect in- or
output, list processes with ps
chmod
to modify file permissions
What's in a process?
Figure © 2016 Julia Evans, all rights reserved; from julia's drawings. Displayed here with personal permission.
help
to execute one and see all of themcat
, grep
, less
, man
, ps
/proc
is a pseudo-filesystem which acts as interface to Linux kernel data
structures
/proc/42
) allow to see
details of process control blocksps
inspects /proc
man ps
for implementation-specific details, following
options are for GNU/Linux)ps -e
shows some details on all processes (IDs, time, etc.)ps -C <name>
shows some details on all processes with the
given name
cat
may be too
short-lived to be seen with ps
/proc/<pid>/status
cat /proc/42/status
voluntary_ctxt_switches
nonvoluntary_ctxt_switches
Bash allows scripting, e.g., while loops with the builtin
command while
:
while <condition>; do <commands>; done
while true; do true; done
true
is a builtin bash command that immediately
returns a true value.while true; do sleep 1; done
sleep
is not builtin, but creates a single-threaded process whose
thread sleeps for the indicated number of seconds before the
process exits.cd clmystery/mystery
head crimescene | grep Alice
crimescene
\(\leadsto\) head
\(\leadsto\) grep
\(\leadsto\) console output
head crimescene > first10lines
grep Alice < first10lines
crimescene
\(\leadsto\) head
\(\leadsto\)
first10lines
\(\leadsto\) grep
\(\leadsto\) console output
File descriptors
Figure © 2018 Julia Evans, all rights reserved; from julia's drawings. Displayed here with personal permission.
POSIX standard describes three descriptors (numbered 0, 1, 2) for every process
“Standard file descriptors” by Jens Lechtenbörger under CC BY-SA 4.0; using UXWing icons: keyboard, monitor, operations; from GitLab
stdin
(e.g., keyboard input)stdout
(e.g., print to screen/terminal)stderr
(e.g., print error message to terminal)Streams of bytes can be redirected
head names.txt > first10names.txt
head
outputs first lines of file names.txt
head
invokes system calls to open and read the file,
which happens via a newly allocated file descriptor>
operator redirects stdout
of process to file
first10names.txt
stdin
head < names.txt
<
operator redirects file to stdin
of process;
here, access of names.txt
via stdin
stdout
of one process to stdin
of another
head names.txt | grep "Steve"
head
sends its stdout
via
pipe operator (|
) to stdin
of process for grep
Pipes
Figure © 2016 Julia Evans, all rights reserved; from julia's drawings. Displayed here with personal permission.
/proc
<pid>
, sub-directory /proc/<pid>/fd
indicates its file descriptors
Use ls -l
to see numbers and their destinations, e.g.:
lrwx------ 1 jens jens 64 Jun 26 15:34 0 -> /dev/pts/3 lrwx------ 1 jens jens 64 Jun 26 15:34 1 -> /dev/pts/3 lrwx------ 1 jens jens 64 Jun 26 15:34 2 -> /dev/pts/3 lr-x------ 1 jens jens 64 Jun 26 15:34 3 -> /dev/tty lr-x------ 1 jens jens 64 Jun 26 15:34 4 -> /etc/passwd
/dev/pts/3
(a so-called pseudo-terminal,
which represents user interaction with the command line)
for stdin
, stdout
, and stderr
/etc/passwd
via file descriptor 4/dev/tty
is
mostly the same
as /dev/pts/3
here)/proc/<pid>/fd
.ps
to identify process ID for given name
ps -o pid,lstart -C <name>
ps
implementations without option -C
, use grep
: ps | grep <name>
ls -l /proc/<pid>/fd
(with process ID identified in previous step)Transfer of rights from principal JDoe to process P1
Figure 7.12 (a) of [Hai19]: copy rights
F1 | F2 | JDoe | P1 | … | |
---|---|---|---|---|---|
JDoe | read | write | |||
P1 | read | write | |||
⋮ |
Figure 7.12 (b) of [Hai19]: special right for transfer of rights
F1 | F2 | JDoe | P1 | … | |
---|---|---|---|---|---|
JDoe | read | write | |||
P1 | use rights of | ||||
⋮ |
Unix permissions
Figure © 2018 Julia Evans, all rights reserved; from julia's drawings. Displayed here with personal permission.
ls
lists files and directories
-l
in “long” formls -l /etc/shadow /usr/bin/passwd
-
rw-
r--
---
1
root
shadow
1465 Jan 21 2015 /etc/shadow
-
rws
r-x
r-x
1
root
root
47032 Jan 27 01:40 /usr/bin/passwd*
ls -ld /tmp
d
rwx
rwx
rwt
14
root
root
20480 Jul 4 13:20 /tmp
-
), directory (d
), symbolic link (l
), …r
), write (w
), execute (x
) (for directories,
“execute” means “traverse”)s
), sticky bit (t
)chmod
man
pagehelp umask
in bash)r
, w
, x
u
, g
, o
for user, group, others, resp.,+
or -
to add or remove a permission,r
, w
, x
, s
, t
(and more)chmod g+w file.txt
adds write permissions for
group members on file.txt
This document is part of an Open Educational Resource (OER) course on Operating Systems. Source code and source files are available on GitLab under free licenses.
Except where otherwise noted, the work “OS10: Processes”, © 2017-2023 Jens Lechtenbörger, is published under the Creative Commons license CC BY-SA 4.0.
In particular, trademark rights are not licensed under this license. Thus, rights concerning third party logos (e.g., on the title slide) and other (trade-) marks (e.g., “Creative Commons” itself) remain with their respective holders.