Talk:COMP 3000 2012 Midterm Material: Difference between revisions
Windowpane (talk | contribs) |
Windowpane (talk | contribs) |
||
Line 165: | Line 165: | ||
Important kill signals: | Important kill signals: | ||
-SIGINT or -2 -> (crtl-C) sends a kill signal to program, can be ignored. | -SIGINT or -2 -> (crtl-C) sends a kill signal to program, can be ignored. SIGINT is also the default signal used by kill. (ie. kill <PID> = kill -2 <PID>) | ||
-SIGSTP -> (crtl-Z) sends suspend program signal, to resume it use fg <pid or jobnumber> or bg <pid or jobnumber> or send SIGCONT | -SIGSTP -> (crtl-Z) sends suspend program signal, to resume it use fg <pid or jobnumber> or bg <pid or jobnumber> or send SIGCONT | ||
-SIGSTOP -> same as SIGSTP, except no shortcut keys and it is unblockable. | -SIGSTOP -> same as SIGSTP, except no shortcut keys and it is unblockable. |
Revision as of 00:32, 26 October 2012
Discussion
Only the facts
I'll be putting up my notes of notes up here. Hopefully people can benefit from these. I'll be summing up the answers from the lab and adding a few more details here and there.
Lab 1
Types of shell commands
Built ins Shell functions binaries (scripts and binaries alias
Shell builtins vs binaries
binaries exist elsewhere faster, no forking needed Kernel functions (IO redirection)
ls -l
1 2 3 4 5 6 7 -rwxr-xr-x 1 root root 104508 Mar 31 2012 /bin/ls
U G O -rwxrwxrwx
Memnonic: 'You go hugo!'
- denotes a regular file d denotes a directory b denotes a block special file c denotes a character special file l denotes a symbolic link p denotes a named pipe
2) 1 link to /bin/ls 3) user root 4) group root 5) size in bytes 6) date last modified 7) path/filename
I/O redirection
<< keyword HEREDOC. Input until program reads specified keyword >> append < read from path > write to path, blow away anything there | pipes
file descriptors
0 stdin 1 stdout 2 stderr 3-9 other
fd redirection
#> where # is a file descriptor a>&b redirects file descriptor a to b.
COMMAND &>> file.txt Appends BOTH STDERR and STDOUT to file.txt
For loops
//For all files in fold that start with l, echo the title for i in l*; do echo $i done
Bg vs fg
Bash waits or doesn't for return Both write to stdout as normal
Shell vars
shell vars only apply to shell. Live in shell environment is more global, but typically a COPY is passed on to child processes envp is a series of keyvalue strings passed in with exec*
Lab2
Processes
ps aux ps -e top
run pstree. notice that cron, upstart-socket, and others are owned by init. These are daemons.
notice that gnome display manager is a child of lightdm. Killing lightdm kills gnome. That's why we had to log into a virtual console
Upstart
init is upstart started by kernel. It's the only think the kernel runs in userspace
shutdown -r now switches to run level 6
shutdown -h now switches to run level zero
symlinks in /etc/init.d point to /lib/init/upstart-job successful sysV to upstart transition
Upstart's entire deal is revamp the ol' sysV boot seq
traditional init process is strictly synchronous, blocking future tasks until the current one has completed.
upstart is async. and allows more parralleissimsimsmmmsm
Logs
/var/log
use lsof to check who's accessing a file.
Rule of thumb. if logfile is generic, then written to by rsyslog (udev, auth, etc) if logfile has program name, written to by that program (apache)
rsyslog daemon that handles syslog protocol handles generic logging for system
Lab 3
Tracing
ltrace, strace Statically linking will make ltrace output nothing.
writing to files
File * f = fopen(path, "w") fprintf(f,"blah") fclose(f)
exec*
the exec family of functions replace the current process image with that of another file/binary. Does not return value if successful, -1 on failure Process keeps same PID execvp() inherits the current process's environment variables execve() needs to have the environment variables passed in as an array of pointers to null terminated strings.
Other
kill sends signals.
used as follows: "kill <-command> <PID of program>"
Important kill signals: -SIGINT or -2 -> (crtl-C) sends a kill signal to program, can be ignored. SIGINT is also the default signal used by kill. (ie. kill <PID> = kill -2 <PID>) -SIGSTP -> (crtl-Z) sends suspend program signal, to resume it use fg <pid or jobnumber> or bg <pid or jobnumber> or send SIGCONT -SIGSTOP -> same as SIGSTP, except no shortcut keys and it is unblockable. -SIGCONT -> Continue signal, resumes a stopped program -SIGFPE -> floating point exception (dividing by zero) -SIGEGV -> Segmentation fault signal. -SIGCHLD -> Signal sent to parent when child terminates. -SIGKILL or -9 -> Unblockable kill signal