CS207 Introduction to Computer Systems Wednesday, 17 May 2023 + From Slack - "With handling SIGINT, my terminal by default echoes back a “^C” to stderr anytime I press ctrl+C. In my interruption handling function, I’m also printing “^C”, so now I’m getting two of those (“^C^C”) anytime I try to interrupt. Is there a way to prevent this?" - "When we fork twice, where do the waits happen?" if fork() != 0 if fork() != 0 wait wait else // child2 dup2, close, whatever else // child1 dup2, close, whatever - "What does fflush() do and why should we use it? Most sites aren’t super helpful about thhis" printf, fprintf, putchar, etc. send output to an output buffer when the system feels like it, it sends the output buffer contents to stdout fflush(stdout) says "send it now" printf("debugging message\n"); // maybe you never see this some-code-that-crashes(); printf("other debugging message\n"); command1 | command2 < file1 + Some questions - What is a process? - What does > do? - What does < do? - What does | do? - List some examples of command lines with | that you might actually use ls -l | wc -l # count files in current dir cat names.txt | grep Han python3 scores.py 06-bombs.txt , then copy/paste into my spreadsheet the terminal font size,etc. pastes into Excel, which I hate python3 scores.py 06-bombs.txt | pbcopy # copies the output to the clipboard $ history | grep '|' 142 cat asdf | pbcopy 261 cat a | pbcopy 328 cat something.txt | wc 344 echo "hi" | wc 345 echo "hi there" | wc 346 echo -n "hi there" | wc 351 ls -l | grep something 469 history | grep "|" 465 ps aux | grep shell208 495 ps aux | grep -c bash ps aux | grep bash | less - DIGRESSION: grep grep = global regular expression print simplest case grep moose file.txt # print all lines from file.txt that contain moose grep "[Mm]oose" file.txt grep -c moose file.txt # just print how many (count) of lines with moose grep -v moose file.txt # print all lines without moose grep -r moose some_directory # grep on all the files in this dir tree grep -c dak dictionary-web-log # (count how many accesses to my online dakota dictionary) - What do these functions do? - fork - exec - signal - pipe - dup2 - wait - fflush (and why would you use it?) - strtok (and why would you use it?) - What is a signal? - What does the "kill" command do? - When you quit VS Code on mantis, do you first click on the bottom left and then select "Close Remote Connection"? - When one of my sample programs is confusing, what do you do? + Processes can be weird - Race conditions