Download CIS 90 - Lesson 11
Transcript
CIS 90 - Lesson 11 Lesson Module Checklist • Slides • WB • • • • • • Flash cards Page numbers 1st minute quiz Web Calendar summary Web book pages Commands • Lab tested and uploaded • Tech file email for Lab 9 ready • Materials uploaded • Backup slides, CCC info, handouts on flash drive • Spare 9v battery for mic 1 CIS 90 - Lesson 11 Introductions and Credits Jim Griffin • Created this Linux course • Created Opus and the CIS VLab • Jim’s site: http://cabrillo.edu/~jgriffin/ Rich Simms • HP Alumnus • Started teaching this course in 2008 when Jim went on sabbatical • Rich’s site: http://simms-teach.com And thanks to: • John Govsky for many teaching best practices: e.g. the First Minute quizzes, the online forum, and the point grading system (http://teacherjohn.com/) 2 CIS 90 - Lesson 11 Student checklist 1) Browse to the CIS 90 website Calendar page • http://simms-teach.com • Click CIS 90 link on left panel • Click Calendar link near top of content area • Locate today's lesson on the Calendar 2) Download the presentation slides for today's lesson for easier viewing 3) Click Enter virtual classroom to join CCC Confer session 4) Connect to Opus using Putty or ssh command 3 CIS 90 - Lesson 11 Instructor: Rich Simms Dial-in: 888-450-4821 Passcode: 761867 Buzz Carlos Elijah Emily Enrique C. Enrique R. Jon M. Jon W. Jordan Joseph JJ Kiernan Maria Mathew Mike C. Michael F. Mike M. Nick L. Patrick Rebecca Ricardo Robert Ruth Steve Tim Troy Tess Email me ([email protected]) a relatively current photo of your face for 3 points extra credit CIS 90 - Lesson 11 Quiz Please answer these questions in the order shown: email answers to: [email protected] (answers must be emailed within the first few minutes of class for credit) 5 CIS 90 - Lesson 11 [ ] Preload White Board with cis*lesson??*-WB [ ] Connect session to Teleconference Session now connected to teleconference [ ] Is recording on? Red dot means recording [ ] Use teleconferencing, not mic Should be greyed out Keep wireless mic transmitter away from cell phone and podium if excess static occurs 6 CIS 90 - Lesson 11 [ ] layout and share apps [ ] Share Foxit, Putty, and Chrome foxit for slides chrome putty vSphere Client 7 CIS 90 - Lesson 11 [ ] Video (webcam) optional [ ] Follow moderator [ ] Double-click on postages stamps 8 CIS 90 - Lesson 11 Universal Fix for CCC Confer: 1) Shrink (500 MB) and delete Java cache 2) Uninstall and reinstall latest Java runtime Control Panel (small icons) General Tab > Settings… 500MB cache size Delete these Google Java download 9 CIS 90 - Lesson 11 vi editor Objectives Agenda • Create and modify text files • Quiz • Questions from last week • more on grep • Review on processes • The vi editor • Wrap up 10 CIS 90 - Lesson 11 Questions 11 CIS 90 - Lesson 11 Questions? Lesson material? Labs? Tests? How this course works? Who questions much, shall learn much, and retain much. - Francis Bacon If you don't ask, you don't get. - Mahatma Gandhi Chinese Proverb 他問一個問題,五分鐘是個傻子,他不問一個問題仍然是一個 傻瓜永遠。 He who asks a question is a fool for five minutes; he who does not ask a question remains a fool forever. 12 CIS 90 - Lesson 11 Test 2 Post Mortem 13 CIS 90 - Lesson 11 Test 2 – Results Missed Missed Missed Missed Missed Missed Missed Missed Missed Missed Missed Missed Missed Missed Missed Q4 = 15 Q24 = 15 Q30 = 14 Q28 = 13 Q25 = 13 Q29 = 12 Q26 = 12 Q21 = 12 Q2 = 10 Q17 = 10 Q27 = 9 Q23 = 9 Q13 = 8 Q20 = 7 Q18 = 7 21 tests submitted Missed Missed Missed Missed Missed Missed Missed Missed Missed Missed Missed Missed Missed Missed Missed Q16 = 7 Q11 = 7 Q3 = 6 Q22 = 6 Q19 = 6 Q12 = 5 Q9 = 4 Q6 = 4 Q15 = 4 Q14 = 4 Q7 = 2 Q5 = 2 Q8 = 1 Q10 = 0 Q1 = 0 Extra Credit Missed Q31 = 18 Missed Q32 = 17 Missed Q33 = 14 6 tests not submitted Correct answers are in /home/cis90/answers on Opus 14 CIS 90 - Lesson 11 CIS 90 Test 2 35 30 Score 25 20 No Practice 15 Practiced 2+ Hrs 10 5 0 12:00 14:24 16:48 19:12 Time 21:36 0:00 Working the practice test tended to result in higher scores and shorter completion times 15 CIS 90 - Lesson 11 Q16) There is a file in the /etc directory named passwd. This file has information on all user accounts including usernames, UIDs, first and last name, etc. What is the absolute pathname of this file? Correct answer: /etc/passwd To check your answer (lesson 4) [simben90@sun-hwa-ii ~]$ ls /etc/passwd /etc/passwd http://www.sodahead.com/unitedstates/what-color-was-george-washingtonswhite-horse/question-636725/ http://kids.britannica.com/comptons/art-55428/General-George-Washington-andhis-staff-welcoming-a-provision-train http://www.mountvernon.org/content/revol utionary-war-princeton-white-horse 16 CIS 90 - Lesson 11 17 CIS 90 - Lesson 11 Housekeeping 18 CIS 90 - Lesson 11 1. Lab 8 due tonight Don’t wait till midnight tonight to see if this worked! Test with an earlier time. at 11:59pm at> cat files.out bigshell > lab08 at> cp lab08 /home/rsimms/turnin/cis90/lab08.$LOGNAME at> <Ctrl-D> 2. A check8 script is available for Lab 8 3. Note: Lab 9 and five posts due next week 4. You can still send me your photo for our class page if you want 3 points extra credit 19 CIS 90 - Lesson 11 20 CIS 90 - Lesson 11 1:00-2:30 PM 21 CIS 90 - Lesson 11 Final Exam Test #3 (final exam) • Must be face-to-face or proctored (not online using CCC Confer). • Room 828 on campus. • Timed test (no 11:59PM grace period) • If you are a long distance student, contact the instructor for options. 22 CIS 90 - Lesson 11 http://simms-teach.com/cis90grades.php • Check your progress on the Grades page • If you haven't already, send me a student survey to get your LOR secret code name • Graded labs & tests are placed in your home directories on Opus • Answers to labs, tests and quizzes are in the /home/cis90/answers directory on Opus 23 CIS 90 - Lesson 11 Current Point Tally As of 4/15/2014 Points that could have been earned: 7 quizzes: 21 points 7 labs: 210 points 2 tests: 60 points 2 forum quarters: 40 points Total: 331 points alatar: 61% (202 of 331 points) anborn: 81% (270 of 331 points) aragorn: 85% (282 of 331 points) arwen: 99% (330 of 331 points) beregond: 0% (0 of 331 points) bilbo: 54% (181 of 331 points) celebrian: 98% (327 of 331 points) dwalin: 95% (317 of 331 points) eomer: 89% (296 of 331 points) faramir: 93% (310 of 331 points) frodo: 90% (300 of 331 points) gwaihir: 106% (351 of 331 points) ioreth: 94% (312 of 331 points) legolas: 87% (291 of 331 points) marhari: 66% (220 of 331 points) orome: 82% (273 of 331 points) pallando: 0% (0 of 331 points) pippen: 67% (225 of 331 points) quickbeam: 91% (304 of 331 points) rian: 0% (0 of 331 points) samwise: 80% (266 of 331 points) shadowfax: 0% (0 of 331 points) strider: 89% (296 of 331 points) theoden: 56% (187 of 331 points) treebeard: 104% (347 of 331 points) tulkas: 85% (282 of 331 points) ulmo: 80% (268 of 331 points) If you are not happy with your current standing contact the instructor ASAP 24 CIS 90 - Lesson 11 Jesse’s checkgrades python script http://oslab.cabrillo.edu/forum/viewtopic.php?f=31&t=773&p=2966 /home/cis90/simben $ checkgrades smeagol Remember, your points may be zero simply because the assignment has not been graded yet. Quiz Quiz Quiz Quiz 1: 2: 3: 4: You You You You earned earned earned earned 3 3 3 3 points points points points out out out out of of of of a a a a possible possible possible possible 3. 3. 3. 3. Use your LOR code name as an argument on the checkgrades command Forum Post 1: You earned 20 points out of a possible 20. Lab Lab Lab Lab 1: 2: 3: 4: You You You You earned earned earned earned 30 30 30 29 points points points points out out out out of of of of a a a a possible possible possible possible 30. 30. 30. 30. You've earned 15 points of extra credit. You currently have a 109% grade in this class. (166 out of 152 possible points.) Jesse is a CIS 90 Alumnus. He wrote this python script when taking the course. It mines data from the website to check how many of the available points have been earned so far. 25 CIS 90 - Lesson 11 CIS Lab Schedule http://webhawks.org/~cislab/ Not submitting tests or lab work? Would like some help? Come to the CIS Lab to work with classmates, lab assistants and instructors on Lab assignments. Rich is in the lab Wednesdays and Fridays from 3:30 - 6:00 PM 26 CIS 90 - Lesson 11 Free CIS 90 Tutoring Available http://www.cabrillo.edu/services/tutorials/ Matt Smithey All students interested in tutoring in CIS 90, 172, and 81 classes need to come directly to the Tutorials Center to schedule, register and fill out some paperwork. This is just a one-time visit. The tutoring will take place at the STEM center and they will log in and log out on a computer you have designated (I will figure out exactly what that means). Matt is available M: 9:00-5:00, T: 9-11 and 2-5, Wed: 9-12 and Th: 9-11 and 3-5. 27 CIS 90 - Lesson 11 grep workout 28 CIS 90 - Lesson 11 Some perfect times to use the grep command: 1) To search through the output of a command for some text command | grep "text string" 2) To search inside one or more files for some text grep "text string" file1 file2 … filen 3) To search (recursively) inside all files in a portion (or all) of the UNIX file tree for some text grep –R "text string" directory 29 CIS 90 - Lesson 11 grep usage – search output of a command Is the CUPS daemon (print service) running right now? /home/cis90/simben $ ps -ef | grep cups root 6251 1 0 Jul31 ? 00:00:04 cupsd -C /etc/cups/cupsd.conf simben90 27027 26966 0 08:47 pts/3 00:00:00 grep cups Yes it is, with PID=6251 30 CIS 90 - Lesson 11 grep practice • Is the cronjob daemon (crond) running right now? • Type the crond PID into the chat window 31 CIS 90 - Lesson 11 grep usage – search output of a command Is the Apache web server (httpd) installed? This shows all installed package names This searches for package names containing "httpd" /home/cis90/simben $ rpm -qa | grep httpd httpd-tools-2.2.15-15.el6.centos.1.i686 httpd-2.2.15-15.el6.centos.1.i686 httpd-manual-2.2.15-15.el6.centos.1.noarch Yes, version 2.2.15 has been installed 32 CIS 90 - Lesson 11 grep practice • Has the mysql-server package been installed on Opus? • If installed on Opus, type the version of mysql in the chat window 33 CIS 90 - Lesson 11 grep usage – search output of a command When were the last 5 times I logged in? /home/cis90/simben $ last | grep $LOGNAME | head -n5 simben90 pts/0 50-0-68-235.dsl. Mon Apr 23 05:39 simben90 pts/6 10.64.25.2 Wed Apr 18 12:48 simben90 pts/5 10.64.25.2 Wed Apr 18 12:48 simben90 pts/4 10.64.25.2 Wed Apr 18 12:48 simben90 pts/1 50-0-68-235.dsl. Wed Apr 18 09:06 - still logged in 16:51 (04:02) 16:51 (04:02) 16:51 (04:03) 10:23 (01:17) This scans the latest wtmp log file and lists your most recent five logins to Opus 34 CIS 90 - Lesson 11 grep practice • For the time period covered by the current wtmp log file. What was the date of your earliest login? • Type your earliest login date into the chat window 35 CIS 90 - Lesson 11 grep usage – search output of a command [rsimms@oslab ~]$ ls /bin/*sh /bin/bash /bin/csh /bin/dash [rsimms@oslab ~]$ ksh $ dash $ sh sh-4.1$ csh /bin/ksh /bin/rbash /bin/sh /bin/tcsh Look familiar? (lab 8) Shows how to compare shells by size and record the biggest one in a file. [rsimms@oslab ~]$ ps -l F S UID PID PPID C PRI 0 S 201 27553 27552 0 80 0 S 201 27651 27553 0 80 0 S 201 27652 27651 0 80 0 S 201 27653 27652 0 80 0 S 201 27654 27653 0 80 0 R 201 27663 27654 0 80 size NI 0 0 0 0 0 0 ADDR SZ - 1308 - 1376 517 - 1307 - 1458 - 1214 [rsimms@oslab ~]$ ps -l | grep csh 0 S 201 27654 27653 0 80 0 - WCHAN - 1458 - TTY pts/0 pts/0 pts/0 pts/0 pts/0 pts/0 TIME 00:00:00 00:00:00 00:00:00 00:00:00 00:00:00 00:00:00 CMD bash ksh dash sh csh ps pts/0 00:00:00 csh pts/0 00:00:00 csh [rsimms@oslab ~]$ ps -l | grep csh > bigshell [rsimms@oslab ~]$ cat bigshell 0 S 201 27654 27653 0 80 0 - 1458 - 36 CIS 90 - Lesson 11 grep practice • For the bash, dash, ksh, sh and csh shells, which shell process uses the least memory? • What command that would redirect the line of output for the command using the least amount of memory to the file smallshell • Type the command you used and its output into the chat window 37 CIS 90 - Lesson 11 grep usage – search inside files How many CIS 90 user accounts are there? /home/cis90/simben $ grep cis90 /etc/passwd | wc -l 29 There are 29 38 CIS 90 - Lesson 11 grep practice • How many CIS 172 accounts are there on Opus? • Type the number of CIS 172 accounts into the chat window 39 CIS 90 - Lesson 11 grep usage – search inside files Example: What is my account information in /etc/passwd? /home/cis90/simben $ grep $LOGNAME /etc/passwd simben90:x:1000:90:Benji Simms:/home/cis90/simben:/bin/bash or /home/cis90/simben $ grep simben90 /etc/passwd simben90:x:1000:90:Benji Simms:/home/cis90/simben:/bin/bash or /home/cis90/simben $ cat /etc/passwd | grep $LOGNAME simben90:x:1000:90:Benji Simms:/home/cis90/simben:/bin/bash username Comment Home directory Shell Group ID (GID) User ID (UID) password (just a placeholder now) Note the field separator used in /etc/passwd is a ":" 40 CIS 90 - Lesson 11 grep practice • Does your user ID in /etc/passwd match the uid output by the id command? • Type your answer (yes or no) and your uid from the id command into the chat window 41 CIS 90 - Lesson 11 grep usage – search inside files in all or part of the file tree Where does the PS1 "prompt" variable get set? /home/cis90/simben $ grep -R "PS1=" /etc/bash* $HOME 2> /dev/null /etc/bash_completion.d/git:# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ ' /etc/bashrc: [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ " /etc/bashrc: # PS1="[\u@\h:\l \W]\\$ " /home/cis90/simben/class/labs/lab04.graded:21) PS1='$PWD $ ' /home/cis90/simben/class/exams/test01.graded:(A32) PS1='\d $ ' /home/cis90/simben/.bash_profile:PS1='$PWD $ ' /home/cis90/simben/lab04.graded:21) PS1='$PWD $ ' /home/cis90/simben/test01.graded:(A32) PS1='\d $ ' It is set more than once during login. We will learn in a future lesson that the one in .bash_profile is done last and is what you end up using. 42 CIS 90 - Lesson 11 grep practice • Find the file in the /usr/lib portion of the file tree that contains "hot pototo dance" (yes, potato is misspelled). • Type the absolute pathname of the file in the chat window. 43 CIS 90 - Lesson 11 grep usage – search inside files in all or part of the file tree Use color with the --color option 44 CIS 90 - Lesson 11 Shell six steps (REVIEW) 45 CIS 90 – Virtual Classroom Example Command /home/cis90/simben $ find / -name /home/cis90/vasjor/1968.egg /home/cis90/cis/1968.egg /home/cis90/hictre/1968.egg /home/cis90/rodduk/basket/1968.egg /home/cis90/lemrob/1968.egg /home/cis90/fahmic/basket/1968.egg /home/cis90/casric/1968.egg /home/cis90/calmic/1968.egg /home/cis90/mosmic/1968.egg /home/cis90/mccpat/1968.egg /home/cis90/matjon/basket/1968.egg /home/cis90/tilbuz/basket/1968.egg /home/cis90/daweli/1968.egg < snipped > /home/cis90/rudtro/1968.egg /home/cis90/keljos/basket/1968.egg /home/cis90/thinic/1968.egg /home/cis90/casenr/1968.egg /home/cis90/fitcon/1968.egg /home/cis90/simben/1968.egg /home/cis90/vivrut/1968.egg /home/cis90/specod/1968.egg /home/cis90/ramjua/1968.egg /home/cis90/lefnic/basket/1968.egg /home/cis90/hormat/1968.egg /home/cis90/simben $ *egg 2> /dev/null On the next slides we will walk through each of the six steps the shell performs for this command 46 CIS 90 – Virtual Classroom OS Prompt Step 1) Prompt Shell System Commands Applications Kernel 2) Parse 3) Search 4) Execute 5) Nap 6) Repeat 48 CIS 90 - Lesson 11 OS Prompt Step /home/cis90/simben $ The shell prompt is output from the bash shell program directed to your terminal device • Benji is using the bash shell. There are many other shells such as sh, ksh and csh. The last field in the line for his account in /etc/passwd determines the shell that is run when he logs in. • The bash program resides in the /bin directory • The command prompt appearance is defined by the PS1 variable. You can output a prompt yourself using echo $PS1 /home/cis90/simben $ grep $LOGNAME /etc/passwd simben90:x:1001:190:Benji Simms:/home/cis90/simben:/bin/bash /home/cis90/simben $ ls -l /bin/bash -rwxr-xr-x. 1 root root 874248 May 10 2012 /bin/bash 49 CIS 90 - Lesson 11 OS Prompt Step /home/cis90/simben $ find / -name *egg 2> /dev/null Benji types this find command in response to the shell prompt 51 CIS 90 - Lesson 11 OS Parse Step 1) Prompt Shell System Commands Applications Kernel 2) Parse 3) Search 4) Execute 5) Nap 6) Repeat 52 CIS 90 - Lesson 11 OS The shell uses spaces to separate options, arguments and redirection Parse Step find / -name *egg 2> /dev/null Parsing RESULTS: The shell must expand filename expansion characters and variables during the parse step. Note there is an invisible <newline> metacharacter at the end of the command Command: find Options and arguments: / -name 1968.egg This will be passed to the command (if the command can be located on the path) Redirection: Connect stderr to /dev/null (the "bit bucket") Note: Because Benji had a 1968.egg file in his home directory, the shell expands *egg to 1968.egg This will be handled by the shell. The command, if loaded, will not see this 54 CIS 90 - Lesson 11 OS Search Step 1) Prompt Shell System Commands Applications Kernel 2) Parse 3) Search 4) Execute 5) Nap 6) Repeat 55 CIS 90 - Lesson 11 OS Search Step Command: find The shell now must search, in order, every directory on Benji’s path to locate the first occurrence of the find command. Benji’s path is defined by the value of his PATH variable 1st directory searched: /usr/lib/qt-3.3/bin 2nd directory searched: /usr/local/bin The shell locates the find command in the 3rd directory searched: /bin /bin directory 4th directory searched: /usr/bin 5th directory searched: /usr/local/sbin 6th directory searched: /usr/sbin 7th directory searched: /sbin 8th directory searched: /home/cis90/simben/../bin 9th directory searched: /home/cis90/simben/bin 10th directory searched: . /home/cis90/simben $ echo $PATH /usr/lib/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/cis90/simben/../bin:/home/cis90/simben/bin:. 56 CIS 90 - Lesson 11 OS Execute Step 1) Prompt Shell System Commands Applications Kernel 2) Parse 3) Search 4) Execute 5) Nap 6) Repeat 57 CIS 90 - Lesson 11 OS Execute Step PID: 1570 PID: 1570 exec() PPID: 1476 PPID: 1476 PID: 1476 PID: 1476 wait() fork() bash PPID: 1475 X find bash PID: 1476 exit() bash PPID: 1475 bash / PPID: 1475 bash executes the find command by cloning itself with a fork() system call to create a new child process. With an exec() system call, the new child process is overlaid with the find code instructions. bash sleeps by making a wait() system call while the find child process runs. The child process makes an exit() system call when it has finished. After that, the parent bash process wakes up and the child process is killed. 58 CIS 90 - Lesson 11 Execute Step OS /home/cis90/simben $ find / -name *egg 2> /dev/null stdout Args: / Options: -name 1968.egg /home/cis90/lovben/1968.egg /home/cis90/wismar/basket/1968.egg /home/cis90/perste/basket/1968.egg /home/cis90/perste/1968.egg /home/cis90/cis/1968.egg /home/cis90/paljay/basket/1968.egg < snipped > find 1 0 2 read directory contents are read using the kernel stdin /dev/null stderr find: `/lost+found': Permission denied find: `/var/empty/sshd': Permission denied find: `/var/log/sssd': Permission denied 60 < snipped > CIS 90 - Lesson 11 This is what the find process might look like A process: • Is provided with parsed & expanded options and arguments from the shell • may read from stdin • may write to stdout • may write error messages to stderr • and may get interrupted from time to time by a signal The find process is running 62 CIS 90 - Lesson 11 OS Nap Step 1) Prompt Shell System Commands Applications Kernel 2) Parse 3) Search 4) Execute 5) Nap 6) Repeat 63 CIS 90 - Lesson 11 OS Nap Step PID: 1570 PID: 1570 exec() bash PPID: 1476 bash bash PPID: 1475 ps find bash PID: 1476 PPID: 1476 PID: 1476 fork() PID: 501 shows The PS command Benji’s find command is runningbash as a child process while the parent bash shell sleeps wait() bash bash PPID: 1475 exit() PPID: 250 / [rsimms@oslab ~]$ ps -l -u simben90 F S UID PID PPID C PRI NI ADDR SZ 5 S 1001 1475 1470 0 80 0 - 3392 0 S 1001 1476 1475 0 80 0 - 1308 0 R 1001 1570 1476 40 80 0 - 1179 WCHAN ? ? ? TTY ? pts/1 pts/1 R=Running (PID 1570 find), S=Sleeping (PID 1476 bash) TIME 00:00:00 00:00:00 00:00:00 CMD sshd bash find 64 CIS 90 - Lesson 11 OS Repeat Step 1) Prompt Shell System Commands Applications Kernel 2) Parse 3) Search 4) Execute 5) Nap 6) Repeat 65 CIS 90 - Lesson 11 OS Repeat Step PID: 1570 PID: 1570 exec() PPID: 1476 PPID: 1476 PID: 1476 PID: 1476 wait() fork() bash PPID: 1475 X find bash PID: 1476 exit() bash PPID: 1475 bash / PPID: 1475 The child process makes an exit() system call when it has finished. The parent bash process wakes up, the child process is killed and we are ready to start the process all over again with the next command. 66 CIS 90 - Lesson 11 Process activity • See if you can do a ps command that illustrates what happens when a user runs a long grep command. • The ps output should show "parent" bash S=Sleeping while the "child" grep command is either R=Running or in D=Uninterruptible sleep (IO) • Start a second login session to observe your processes • Write your grep PID and status into the chat window when done /home/cis90/simben $ grep -r "pototo" /usr/lib /usr/src /home/cis90/guest $ ps -lu simben90 67 CIS 90 - Lesson 11 Review of Signals 68 CIS 90 - Lesson 11 Signals 69 CIS 90 - Lesson 11 This is what a process might look like A process: • Is provided with parsed/expanded options and arguments from the shell • may read from stdin • may write to stdout • may write error messages to stderr • and may get interrupted from time to time by a signal A process is a program that has been loaded into memory and is either running (executing instructions) or waiting to run 70 CIS 90 - Lesson 11 Signals The result of sending a signal to a process: This running process gets signal 20 (SIGTSTP) • be ignored • default action (die) • execute some predefined function 71 CIS 90 - Lesson 11 Signals SIGHUP SIGINT SIGQUIT SIGILL SIGTRAP SIGIOT SIGBUS SIGFPE SIGKILL SIGUSR1 SIGSEGV SIGUSR2 SIGPIPE SIGALRM SIGTERM 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Hangup (POSIX) Terminal interrupt (ANSI) Ctrl-C Terminal quit (POSIX) Ctrl-\ Illegal instruction (ANSI) Trace trap (POSIX) IOT Trap (4.2 BSD) BUS error (4.2 BSD) Floating point exception (ANSI) Kill (can't be caught or ignored) (POSIX) User defined signal 1 (POSIX) Invalid memory segment access (ANSI) User defined signal 2 (POSIX) Write on a pipe with no reader, Broken pipe (POSIX) Alarm clock (POSIX) Termination (ANSI) Use kill –l to see all signals 72 CIS 90 - Lesson 11 Signals SIGSTKFLT SIGCHLD SIGCONT SIGSTOP SIGTSTP SIGTTIN SIGTTOU SIGURG SIGXCPU SIGXFSZ SIGVTALRM SIGPROF SIGWINCH SIGIO SIGPWR 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Stack fault Child process has stopped or exited, changed (POSIX) Continue executing, if stopped (POSIX) Stop executing(can't be caught or ignored) (POSIX) Terminal stop signal (POSIX) Ctrl-Z or Ctrl-F Background process trying to read, from TTY (POSIX) Background process trying to write, to TTY (POSIX) Urgent condition on socket (4.2 BSD) CPU limit exceeded (4.2 BSD) File size limit exceeded (4.2 BSD) Virtual alarm clock (4.2 BSD) Profiling alarm clock (4.2 BSD) Window size change (4.3 BSD, Sun) I/O now possible (4.2 BSD) Power failure restart (System V) Use kill –l to see all signals 73 CIS 90 - Lesson 11 Signals Signals are asynchronous messages sent to processes They can result in one of three courses of action: 1. be ignored, 2. default action (die) 3. execute some predefined function. Signals are sent: kill command Using the kill command: $ kill -# PID • Where # is the signal number and PID is the process id. • if no number is specified, SIGTERM (-15) is sent. Using special keystrokes • limited to just a few signals • limited to when you have control of the keyboard Use kill –l to see all signals 74 CIS 90 - Lesson 11 Target Practice 75 CIS 90 - Lesson 11 Activity 1) Run the annoy program 2) Try sending it a SIGINT with Ctrl-C 3) Try sending it a SIGQUIT with Ctrl-\ 4) Bring up another terminal and try signals 1 through 64 • Use ps –u $LOGNAME to find the annoy PID • • • • Try kill -1 PID Try kill -2 PID Try kill -3 PID and so forth … OR • • • • Try killall -1 annoy Try killall -2 annoy Try killall -3 annoy and so forth … 5) Write the signals that kill annoy into the chat window 76 CIS 90 - Lesson 11 Using & to run a command in the background 77 CIS 90 - Lesson 11 Job Control Using & to run a command in the background After running Firefox in the foreground it's not possible to enter more commands until Firefox is closed 78 CIS 90 - Lesson 11 Job Control Using & to run a command in the background Job Control A feature of the bash shell & Append to a command to run it in the background After running Firefox in the background, it is still possible to enter more commands. 79 CIS 90 - Lesson 11 & append to a command to run it in the background Example 1 /home/cis90/simben $ grep -r potato /usr /opt 2> /dev/null No prompt For long running commands or scripts you must wait for the command to finish before you type more commands Example 2 /home/cis90/simben $ grep -r potato /usr /opt [1] 21175 /home/cis90/simben $ date Tue Apr 15 14:43:09 PDT 2014 2> /dev/null & Hit enter to get the prompt and continue working while the find command runs in the background 80 CIS 90 - Lesson 11 Job Control (Review) 81 CIS 90 - Lesson 11 Job Control A feature of the bash shell & Append to a command to run it in the background bg Resumes a suspended job in the background fg Brings the most recent background process to the foreground jobs Lists all background jobs Use jobs, bg, fg to list and resume jobs in the foreground or background 82 CIS 90 - Lesson 11 Job Control A feature of the bash shell When a process is running (status=R) the user can stop it (status=T) and choose whether it runs in the background or foreground 83 CIS 90 - Lesson 11 Job Control A feature of the bash shell $ Command $ Command & Running in Foreground Ctrl-F (CIS 90 students) fg Ctrl-Z (everyone else) fg Running in Background Stopped bg Use the jobs command to view stopped and background jobs 84 CIS 90 - Lesson 11 Job Control Find out with keystroke combination is configured to suspend a process /home/cis90ol/simmsben $ stty -a speed 38400 baud; rows 24; columns 80; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^F; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; -parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts -cdtrdsr -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke /home/cis90ol/simmsben $ In this case it is Ctrl-F that will be used to suspend a process How is yours configured? 85 CIS 90 - Lesson 11 Job Control Managing jobs /home/cis90ol/simmsben $ sleep 120 Ctrl-Z or Ctrl-F (to suspend process) [1]+ Stopped sleep 120 /home/cis90ol/simmsben $ sleep 110 Ctrl-Z or Ctrl-F (to suspend process) [2]+ Stopped sleep 110 /home/cis90ol/simmsben $ sleep 100 Ctrl-Z or Ctrl-F (to suspend process) [3]+ Stopped sleep 100 /home/cis90ol/simmsben $ jobs [1] Stopped sleep 120 [2]- Stopped sleep 110 [3]+ Stopped sleep 100 Lets start up 3 sleep commands and suspend each of them. Note: The sleep command is a simple way to run a command that will take awhile to finish. sleep 120 will last 120 seconds before it is finished. 86 CIS 90 - Lesson 11 Job Control Managing jobs /home/cis90ol/simmsben $ jobs [1] Stopped sleep 120 [2]- Stopped sleep 110 [3]+ Stopped sleep 100 /home/cis90ol/simmsben F S UID PID PPID 0 S 1082 5364 5363 0 T 1082 5452 5364 0 T 1082 5453 5364 0 T 1082 5454 5364 0 R 1082 5459 5364 $ ps -l C PRI NI 0 75 0 0 75 0 0 75 0 0 75 0 0 77 0 ADDR SZ - 1168 929 929 929 - 1054 WCHAN wait finish finish finish - TTY pts/2 pts/2 pts/2 pts/2 pts/2 TIME 00:00:00 00:00:00 00:00:00 00:00:00 00:00:00 CMD bash sleep sleep sleep ps Note, all three processes are sTopped 87 CIS 90 - Lesson 11 Job Control Managing jobs /home/cis90ol/simmsben $ bg 2 Let's resume job 2 in the background [2]- sleep 110 & /home/cis90ol/simmsben $ jobs [1]- Stopped sleep 120 [2] Running sleep 110 & [3]+ Stopped sleep 100 /home/cis90ol/simmsben $ bg 1 Let's resume job 1in the background [1]- sleep 120 & /home/cis90ol/simmsben $ jobs [1] Running sleep 120 & [2]- Running sleep 110 & [3]+ Stopped sleep 100 /home/cis90ol/simmsben $ fg 3 sleep 100 Let's resume job 1 in the foreground At this point we lose control of the keyboard again until sleep 100 is finished 88 CIS 90 - Lesson 11 Job Control Managing jobs /home/cis90ol/simmsben $ jobs [1]- Done sleep 120 [2]+ Done sleep 110 Background jobs are all done! 89 CIS 90 - Lesson 11 Review of Load Balancing 90 CIS 90 - Lesson 11 Load Balancing The at command: • • • • reads from stdin for a list of commands to run runs those commands at the specified time Any output from those commands will be emailed Use atq and atrm to manage scheduled commands Use at to schedule commands to run in the future 91 CIS 90 - Lesson 11 Load Balancing Managing queued jobs at now + 5 minutes at now + 1 hour at 7:58AM Ways to specify future times at 7:47PM 5/5/2012 at teatime 92 CIS 90 - Lesson 11 Load Balancing Managing queued jobs /home/cis90/simben 25 2011-11-12 28 2011-12-12 27 2011-11-19 26 2011-11-12 24 2011-11-12 $ atq 14:09 03:00 12:10 16:00 12:14 /home/cis90/simben /home/cis90/simben 25 2011-11-12 28 2011-12-12 27 2011-11-19 26 2011-11-12 $ atrm 24 $ atq 14:09 a simben90 03:00 a simben90 12:10 a simben90 16:00 a simben90 /home/cis90/simben $ jobs a a a a a simben90 simben90 simben90 simben90 simben90 The atq command lists jobs queued to run in the future The atrm command is used to remove jobs from the queue Note: The jobs command lists processes running or suspended in the background and is NOT used for at commands. 93 CIS 90 - Lesson 11 Load Balancing Try it yourself with your own terminal device and username: [rsimms@oslab ~]$ tty /dev/pts/4 These should match [rsimms@oslab ~]$ at now+2 minutes at> echo "Take Benji for a walk" | mail -s "walk the dog" $LOGNAME at> echo "Read your mail" > /dev/pts/4 at> <EOT> job 11 at 2012-11-05 11:02 [rsimms@oslab ~]$ atq 11 2012-11-05 11:02 a rsimms [rsimms@oslab ~]$ Type what happens in the chat window: 94 CIS 90 - Lesson 11 text editors 95 CIS 90 - Lesson 11 There are lots of text editors … Windows notepad notepad++ textpad Text editors and word processors are different! Mac • Word processors are used by many different people to create documents containing text and graphics. • Text editors are used by programmers to develop software and web designers to create web sites. TextWrangler Linux gedit emacs nano vi jove Thanks Maria! 96 CIS 90 - Lesson 11 Word processors allow a rich set of formatting (fonts, sizes, styles, color) and graphics to be added to documents. Text editors use color to show the language syntax 97 CIS 90 - Lesson 11 vi 101 98 CIS 90 - Lesson 11 On Opus we are actually running VIM /home/cis90/simben $ type -a vi vi is aliased to `vim' vi is /bin/vi /home/cis90/simben $ type vim vim is hashed (/usr/bin/vim) History: • The original vi code was written by Bill Joy for BSD Unix • Bill Joy co-founded Sun Microsystems in 1982 • vi (for "visual") • vim is an enhanced version of vi 99 CIS 90 - Lesson 11 /home/cis90/simben $ /home/cis90/simben $ vi dogbone Type this 100 CIS 90 - Lesson 11 See this … Take your hands OFF THE MOUSE – don’t use it in vi! 101 CIS 90 - Lesson 11 Tap the letter i key (for insert) Keep your hands OFF THE MOUSE – don’t use it in vi! 102 CIS 90 - Lesson 11 See this … Keep your hands OFF THE MOUSE – don’t use it in vi! 103 CIS 90 - Lesson 11 Very carefully type these five lines Keep your hands OFF THE MOUSE – don’t use it in vi! 104 CIS 90 - Lesson 11 Have your neighbor check that your five lines are PERFECT Keep your hands OFF THE MOUSE – don’t use it in vi! 105 CIS 90 - Lesson 11 Tap the esc key Keep your hands OFF THE MOUSE – don’t use it in vi! 106 CIS 90 - Lesson 11 Type a : Keep your hands OFF THE MOUSE – don’t use it in vi! 107 CIS 90 - Lesson 11 Type wq Keep your hands OFF THE MOUSE – don’t use it in vi! 108 CIS 90 - Lesson 11 Tap the enter key /home/cis90/simben $ vi dogbone /home/cis90/simben $ 109 CIS 90 - Lesson 11 Add execute permissions and try your new script /home/cis90/simben $ chmod +x dogbone /home/cis90/simben $ dogbone What is your name? Benji What is your favorite bone? chicken Hi Benji, your favorite bone is chicken /home/cis90/simben $ 110 CIS 90 - Lesson 11 vi COMMAND mode INSERT mode command LINE mode 111 CIS 90 - Lesson 11 /home/cis90/simben $ cp letter myletter /home/cis90/simben $ vi myletter COMMAND mode : i esc INSERT mode esc Command LINE mode 112 CIS 90 - Lesson 11 vi Moving around in a file Use in COMMAND mode h moves the cursor one character to the left j moves the cursor down one line k moves the cursor up one line l moves the cursor one character to the right Try typing a number in front of these commands and notice what happens ^d scrolls down 10 lines ^u scrolls up 10 lines ^f page forward one page ^b page back one page With vim (not vi) you can use arrow and / page keys instead of these letter commands 113 CIS 90 - Lesson 11 vi Moving around in a file Use in COMMAND mode w moves the cursor one "word" forward b moves the cursor one "word" back Try typing a number in front of these commands and notice what happens 0 (zero) moves the cursor to the beginning of the line $ moves the cursor to the end of the line G moves the cursor to the last line in the file 1G moves the cursor to the first line in the file 105G moves the cursor to line 105 / 114 CIS 90 - Lesson 11 vi Saving and Quiting Use in command LINE mode :w writes any changes to the file you are editing (like Save) :q quits vi if you have saved your changes :q! quits vi even if you haven’t saved changes :wq writes and quits :wq! writes and quits vi even if you haven’t saved changes 115 CIS 90 - Lesson 11 vi Reading in and Writing out files Use in command LINE mode :w filename saves your file to a new name (like Save As) :w! filename saves your file to a new name overwriting any previous data :r filename reads in the contents of filename starting from the cursor position :e filename replaces the current content with the content from filename :%s /string1/string2/g replaces all string1 with string2 in the file 116 CIS 90 - Lesson 11 vi Entering INSERT mode From COMMAND mode. i Ready to insert characters immediately before the current cursor position I Ready to insert characters at the start of the current line a Ready to append characters immediately after the current cursor position A Ready to append characters at the end of the current line o Ready to input characters in a new line that opens up below the cursor O Ready to input characters in a new line that opens up above the cursor / 117 CIS 90 - Lesson 11 vi Cut, Copy, Pasting Commands Use in COMMAND mode x Deletes the current character r Replace the current character with the character you type next dw Deletes the current word dd Deletes the current line D Deletes to the end of the line yy Copies a line to the clipboard buffer p Pastes whatever is in the clipboard buffer below the current cursor P Pastes whatever is in the clipboard buffer above the current cursor 118 CIS 90 - Lesson 11 vi Miscellaneous Useful Commands Use in COMMAND mode. ^g Tells you the filename you are editing and what line your cursor is on u Undoes the last command you executed ^r Undo the undo (redo) . Repeats the last command you executed /string Searches for the string of characters in the file n Finds the next occurrence of the current search string looking down the file N Finds the next occurrence of the current search string looking up the file ~ Changes the case of the current character 119 CIS 90 - Lesson 11 Use vi to edit your edits/text.err file This is line number1. This is line number 1. Thi sis line line number 2. his is line number3.line number3. This is This is line #4. this number5 is line . Here is line number 6. This is lamw number 7. Thi is line nunber9. This is line number10. This This This This This This This This This This is is is is is is is is is is line line line line line line line line line line number number number number number number number number number number 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. Copy your corrected file into the chat window when finished 120 CIS 90 - Lesson 11 http://vim.wikia.com/wiki/Main_Page Tips and tricks for VIM users 121 CIS 90 - Lesson 11 The Mug of vi http://nostarch.com/mug.htm 122 CIS 90 - Lesson 11 /bin/mail and vi /home/cis90/simmsben $ mail roddyduk Subject: Good bones Hey Duke, I really appreciate thatbone you sent me last week. Let me knwo if you want to go mark some fench posts this weekend. Later, Ben You are composing a message and you spot some typos … CRUD … what can you do? 123 CIS 90 - Lesson 11 /bin/mail and vi /home/cis90/simmsben $ mail roddyduk Subject: Good bones Hey Duke, I really appreciate thatbone you sent me last week. Let me knwo if you want to go mark some fench posts this weekend. Later, Ben ~v Well … you could try the ~v command 124 CIS 90 - Lesson 11 /bin/mail and vi The message is loaded into vi where changes or additions can be made. :wq is used to save and quit vi 125 CIS 90 - Lesson 11 /bin/mail and vi /home/cis90/simmsben $ mail roddyduk Subject: Good bones Hey Duke, I really appreciate thatbone you sent me last week. Let me knwo if you want to go mark some fench posts this weekend. Later, Ben ~v (continue) . Cc: /home/cis90/simmsben $ The earlier text with typos is still showing, however the corrected version is what is actually sent. 126 CIS 90 - Lesson 11 /bin/mail and vi /home/cis90/roddyduk $ mail Mail version 8.1 6/6/93. Type ? for help. "/var/spool/mail/roddyduk": 1 message 1 unread >U 1 [email protected] Mon Nov 10 20:25 22/782 "Good bones" & 1 Message 1: From [email protected] Mon Nov 10 20:25:32 2008 Date: Mon, 10 Nov 2008 20:25:32 -0800 From: Benji Simms <[email protected]> To: [email protected] Subject: Good bones Hey Duke, I really appreciate that bone you sent me last week. Let me know if you want to go mark some fence posts this weekend. Later, Ben The message Duke reads has all the typos fixed. & 127 CIS 90 - Lesson 11 Fix an email message before sending /home/cis90/simben/edits $ mail rsimms Subject: test of vi sdkfjas;dflkjas;lkdfj ~v (continue) . EOT /home/cis90/simben/edits $ In vi: • Use i to enter insert mode • make changes • save with <Esc>:wq 128 CIS 90 - Lesson 11 Lab 9 will help you start building your vi skills! Instructor: remember to mail students the tech file! ~/cis90/lab09/mail-tech-all 129 CIS 90 - Lesson 11 A Tangent on Spell 130 CIS 90 - Lesson 11 spell command /home/cis90/roddyduk/edits $ cat text Welcome to the CIS 90 class !! /home/cis90/roddyduk/edits $ spell text CIS spell command flags CIS as misspelled word. How can we add CIS to the dictionary? 131 CIS 90 - Lesson 11 spell command /home/cis90/roddyduk/edits $ cat text Welcome to the CIS 90 class !! /home/cis90/roddyduk/edits $ spell text CIS How can we add CIS to the dictionary? /home/cis90/roddyduk/edits $ man spell Hmmm. No man page No manual entry for spell for spell ???????????? /home/cis90/roddyduk/edits $ type spell spell is hashed (/usr/bin/spell) /home/cis90/roddyduk/edits $ file usr/bin/spell /usr/bin/spell: Bourne shell script text executable /home/cis90/roddyduk/edits $ cat /usr/bin/spell #!/bin/sh # aspell list mimicks the standard unix spell program, roughly. cat "$@" | aspell list --mode=none | sort -u /home/cis90/roddyduk/edits $ OK, the actual command is aspell 132 CIS 90 - Lesson 11 spell command ASPELL(1) Aspell Abbreviated User’s Manual ASPELL(1) NAME aspell - interactive spell checker SYNOPSIS aspell [options] <command> DESCRIPTION aspell is a utility that can function as an ispell -a replacement, as an independent spell checker, as a test utility to test out Aspell features, and as a utility for managing dictionaries. COMMANDS <command> is one of: -?,help display the help message -c,check file to spell-check a file There must be a way to add CIS …. but … lets try google 133 CIS 90 - Lesson 11 spell command How to add words to your dictionary Googling "linux aspell personal dictionary" yields this page Bingo! Thank you Samat Jain 134 CIS 90 - Lesson 11 spell command /home/cis90/roddyduk/edits $ cd /home/cis90/roddyduk $ echo "personal_ws-1.1 en 0" > /home/cis90/roddyduk $ echo "CIS" >> .aspell.en.pws /home/cis90/roddyduk $ cd edits/ /home/cis90/roddyduk/edits $ spell text .aspell.en.pws This is how you would add your own custom dictionary to be used with spell checks 135 CIS 90 - Lesson 11 /home/cis90/simben $ cat edits/spellk Spell Check Eye halve a spelling chequer It came with my pea sea It plainly marques four my revue Miss steaks eye kin knot sea. Eye strike a key and type a word And weight four it two say Weather eye am wrong oar write It shows me strait a weigh. As soon as a mist ache is maid It nose bee fore two long And eye can put the error rite Its rare lea ever wrong. Eye have run this poem threw it I am shore your pleased two no Its letter perfect awl the weigh My chequer tolled me sew. How would you add "chequer" (the British spelling) to your personal dictionary? Copy the commands used into the chat window when finished /home/cis90/simben $ spell edits/spellk chequer $ echo "personal_ws-1.1 en 0" > ~/.aspell.en.pws $ echo "chequer" >> ~/.aspell.en.pws 136 CIS 90 - Lesson 11 Wrap up 137 CIS 90 - Lesson 11 New commands: vi Run vi editor New Files and Directories: na na 138 CIS 90 - Lesson 11 Next Class Assignment: Check Calendar Page on web site to see what is due next week. Quiz questions for next class: • How do you send a SIGKILL to one of your own processes? • What vi command is used to exit vi without saving any of the changes you made? • What vi commands are used for copy and paste? 139 CIS 90 - Lesson 11 Backup 140 CIS 90 - Lesson 11 The mystery of Ctrl-Z vs Ctrl-F 141 CIS 90 - Lesson 11 Signals Special keystrokes /home/cis90/roddyduk $ stty -a speed 38400 baud; rows 26; columns 78; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^F; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; [rsimms@opus ~]$ stty -a speed 38400 baud; rows 39; columns 84; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; Why does the keystroke to send a Suspend (SIGTSTP or 20) signal differ between roddyduk (^F or Ctrl-F) and rsimms (^Z or Ctrl-Z)? 142 CIS 90 - Lesson 11 Job Control A feature of the bash shell Ctrl-Z or Ctrl-F (sends SIGTSTP 20 signal) • Stops (suspends) a foreground process [rsimms@opus ~]$ [1]+ Stopped PID 7728 is stopped Ctrl-Z is tapped which stops the sleep command sleep 5 [rsimms@opus ~]$ F S UID PID 5 S 201 5368 0 S 201 5369 5 S 201 6203 0 S 201 6204 0 T 201 7728 0 R 201 7730 [rsimms@opus ~]$ PPID 5365 5368 6200 6203 6204 5369 C PRI 0 75 0 76 0 75 0 75 0 75 0 78 NI 0 0 0 0 0 0 ADDR SZ - 2460 - 1165 - 2491 - 1165 926 - 1062 WCHAN wait finish - TTY ? pts/0 ? pts/6 pts/6 pts/0 TIME 00:00:00 00:00:00 00:00:00 00:00:00 00:00:00 00:00:00 CMD sshd bash sshd bash sleep ps 143 CIS 90 - Lesson 11 Job Control A feature of the bash shell bg command • Resumes a suspended job in the background [rsimms@opus ~]$ [1]+ Stopped [rsimms@opus ~]$ [1]+ sleep 5 & [rsimms@opus ~]$ PID 7728 is gone bg resumes the sleep command sleep 5 [rsimms@opus ~]$ F S UID PID 5 S 201 5368 0 S 201 5369 5 S 201 6203 0 S 201 6204 0 R 201 7742 [rsimms@opus ~]$ PPID 5365 5368 6200 6203 5369 C PRI 0 75 0 76 0 75 0 75 0 78 NI 0 0 0 0 0 ADDR SZ - 2460 - 1165 - 2491 - 1165 - 1061 WCHAN wait - TTY ? pts/0 ? pts/6 pts/0 TIME 00:00:00 00:00:00 00:00:00 00:00:00 00:00:00 CMD sshd bash sshd bash ps 144 CIS 90 - Lesson 11 Signals Jim's app script This is why Ctrl-F (suspend) stopped working and we had to use Ctrl-Z 145 CIS 90 - Lesson 11 Tangent on bg and SIGCONT 146 CIS 90 - Lesson 11 Signals What is signal 18? Running process gets a signal 147 CIS 90 - Lesson 11 Signals SIGSTKFLT SIGCHLD SIGCONT SIGSTOP SIGTSTP SIGTTIN SIGTTOU SIGURG SIGXCPU SIGXFSZ SIGVTALRM SIGPROF SIGWINCH SIGIO SIGPWR 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Stack fault Child process has stopped or exited, changed (POSIX) Continue executing, if stopped (POSIX) Stop executing(can't be caught or ignored) (POSIX) Terminal stop signal (POSIX) Ctrl-Z or Ctrl-F Background process trying to read, from TTY (POSIX) Background process trying to write, to TTY (POSIX) Urgent condition on socket (4.2 BSD) CPU limit exceeded (4.2 BSD) File size limit exceeded (4.2 BSD) Virtual alarm clock (4.2 BSD) Profiling alarm clock (4.2 BSD) Window size change (4.3 BSD, Sun) I/O now possible (4.2 BSD) Power failure restart (System V) Signal 18 continues a stopped process ... isn’t that what bg does? 148 CIS 90 - Lesson 11 The bg command is used to resume a stopped process /home/cis90/roddyduk $ sleep 60 Ctrl-F (or Ctrl-Z) typed here [1]+ Stopped sleep /home/cis90/roddyduk $ bg [1]+ sleep 60 & /home/cis90/roddyduk $ jobs [1]+ Running sleep /home/cis90/roddyduk $ jobs [1]+ Running sleep /home/cis90/roddyduk $ jobs [1]+ Done sleep /home/cis90/roddyduk $ 60 60 & 60 & 60 bg resumed the stopped process which runs till it is finished 149 CIS 90 - Lesson 11 Instead of using bg to resume a stopped process in the background, lets try a SIGCONT (signal 18) instead /home/cis90/roddyduk $ sleep 60 Ctrl-F (or Ctrl-Z) typed here [1]+ Stopped sleep 60 /home/cis90/roddyduk $ ps -l F S UID PID PPID C PRI NI ADDR SZ 0 S 1000 10705 10704 0 76 0 - 1165 0 T 1000 10743 10705 0 75 0 926 0 R 1000 10744 10705 0 78 0 - 1051 /home/cis90/roddyduk $ jobs [1]+ Stopped sleep 60 /home/cis90/roddyduk $ kill -18 10743 /home/cis90/roddyduk $ jobs [1]+ Running sleep 60 & /home/cis90/roddyduk $ ps -l F S UID PID PPID C PRI NI ADDR SZ 0 S 1000 10705 10704 0 75 0 - 1165 0 S 1000 10743 10705 0 85 0 926 0 R 1000 10746 10705 0 77 0 - 1050 /home/cis90/roddyduk $ jobs [1]+ Running sleep 60 & /home/cis90/roddyduk $ jobs [1]+ Running sleep 60 & /home/cis90/roddyduk $ jobs [1]+ Done sleep 60 WCHAN wait finish - TTY pts/0 pts/0 pts/0 TIME 00:00:00 00:00:00 00:00:00 CMD bash sleep ps WCHAN wait 322800 - TTY pts/0 pts/0 pts/0 TIME 00:00:00 00:00:00 00:00:00 CMD bash sleep ps Note sending a 18 signal or using the bg command will resume a stopped process 150