COMP 3000 2012 Week 5 Notes: Difference between revisions
added lecture notes |
mNo edit summary |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
** fork() | ** fork() | ||
*** creates a new process | *** creates a new process | ||
*** creates own distinct address space | |||
*** different return values for parent and child | *** different return values for parent and child | ||
*** copies state, doesn't share | *** copies state, doesn't share | ||
Line 21: | Line 22: | ||
*** zero is normal exit | *** zero is normal exit | ||
*** non-zero is abnormal | *** non-zero is abnormal | ||
*** magic! see: | *** magic! see: [http://git.minix3.org/?p=minix.git;a=blob;f=lib/libc/stdlib/exit.c;h=c5bcd6725960f5244eed04a53659daa1b49a8194;hb=HEAD source for exit(int) in minix] | ||
** wait(int* stat_loc) | ** wait(int* stat_loc) | ||
*** blocks until a child terminates | *** blocks until a child terminates | ||
** waitpid(pid_t pid, int* stat_loc, int options) | ** waitpid(pid_t pid, int* stat_loc, int options) | ||
*** blocks until child with given pid terminates | *** blocks until child with given pid (process id) terminates | ||
* process information | * process information | ||
** compare the output of strace and ltrace | ** compare the output of strace and ltrace |
Latest revision as of 06:03, 6 October 2012
Processes
- how a process starts
- fork()
- creates a new process
- creates own distinct address space
- different return values for parent and child
- copies state, doesn't share
- modern unix doesn't actually copy, it just pretends that it copies
- "[...] which is the story of virtual memory." -Anil
- execve(const char *path, char *const argv[], char *const envp[])
- when a process runs execve, it commits suicide and hands its process over to the new execution
- note that the arrays themselves are null terminated
- copies state, doesn't share
- envp are environment variables
- file descriptors stay open
- so if you redirect file descriptors for original process, they stay redirected
- env
- command that dumps environment variables
- fork()
- how a process ends
- exit(int return)
- zero is normal exit
- non-zero is abnormal
- magic! see: source for exit(int) in minix
- wait(int* stat_loc)
- blocks until a child terminates
- waitpid(pid_t pid, int* stat_loc, int options)
- blocks until child with given pid (process id) terminates
- exit(int return)
- process information
- compare the output of strace and ltrace
- tells you what the library is doing before it gets to the system level
- compare the output of strace and ltrace
- system calls
- open
- creates a file descriptor
- close
- read
- write
- seek
- chown
- the chgrp command uses the lchown system call
- chmod
- unlink
- mmap
- map to memory
- forward reference to the story of virtual memory
- open