11. Processes
Files and filesystems
Filesystem objects:
- files
- directories
- symlinks
- devices
- pipes (aka FIFOs)
- sockets (aka i've got a hole in me pocket) - async!
 
- …
- non-strictness (but…)
- useful directories of Linux-based system
Mounting
- virtual filesystems (/proc, /sys, /dev, thousands of them)
- e. g. mount /dev/sda1 /mnt/disk/ 
 
Putting in all together
statstat(const char *pathname, struct stat *statbuf);
- struct stat 
- note special types *_t (mostly unsigned integers, filesystem type depended) 
- stat utility 
Process
- PID. Process creation, process tree ps -ef --forest 
- Parent_process: child, zombie, orphan, PID 1 
 
exec (IRL many others)
- keeps PID 
- replaces memory
- inherits open files and environment 
- new PID
- copy memory (probably COW, e. g. no copy for .text) 
- copy environment variables - ⇒ cannot change parent environment 
- can be re-created (see main(argc, char *argv[], char *envp[])) 
 
- inherit open files (descriptors) 
- fork() returns - child PID to parent
- 0 to child
 
- wait(NULL) 
- macros to decode wstatus 
I/O redirection for child
- cmd > file - fork() 
- child closes stdout (descriptor 1) and opens file (at this descriptor) 
- exec(cmd) 
- parent waits for child
 
- cmd < file - guess what   
 
- cmd1 | cmd2 - parent creates a pipe pair
- parent forks to child (1.) - closes stdout (descriptor 1)
- dups writeable part of pipe (1 element) - ⇒ stdout becames pipe[1]
- closes readable part of pipe (for current PID only)
- execs cmd1 (now writing to pipe[1]) 
 
 
- parent forks - closes stdin (descriptor 0)
- dups readable part of pipe (0 element) - ⇒ stdin becames pipe[0]
- closes writeable part of pipe (for current PID only)
- execs cmd2 (now reading from pipe[0]) 
 
 
- parent waits for both childs 
 
H/W
TODO
