Presentation is loading. Please wait.

Presentation is loading. Please wait.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to UNIX / Linux - 8 Dr. Jerry Shiao, Silicon Valley University.

Similar presentations


Presentation on theme: "SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to UNIX / Linux - 8 Dr. Jerry Shiao, Silicon Valley University."— Presentation transcript:

1 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to UNIX / Linux - 8 Dr. Jerry Shiao, Silicon Valley University

2 SILICON VALLEY UNIVERSITY CONFIDENTIAL 2 Introduction UNIX/Linux Course Section 8  Processes What is a Process?  UNIX creates a process when External Command or Shell Script executes, removes a process when command or script terminates. Process Hierarchy and CPU Scheduling.  Time-Sharing System. Concept of a Process, Multiple Process.  Execution of External Command or Shell Script. Process Attributes. Process and Job Control  Foreground and Background Processes.  Sequential and Parallel Processes.  Abnormal Termination of Commands and Processes

3 SILICON VALLEY UNIVERSITY CONFIDENTIAL 3 Summer 2015 Introduction UNIX/Linux Course  Processes  UNIX system creates process every time external command executes and deletes process when external command completes.  Consists of: Executing program code. Process State  Registers: Fast memory.  Ready/Running/Waiting/Swapped/Zombie Set of resources (i.e. open files). Internal kernel data (i.e. struct task_struct). Address space. One or more threads of execution. Data section (i.e. global variables).

4 SILICON VALLEY UNIVERSITY CONFIDENTIAL 4 Summer 2015 Introduction UNIX/Linux Course  Processes  Time-Sharing System (UNIX) – Multiple Processes execute simultaneously.  Scheduling Policy: Set of Rules to select Process for Execution. Fast process response time, good throughput background jobs, avoid process starvation, reconcilitate low and high priority processes. Time sharing principle based on timer interrupts.  Each process has time slice or quantum. When quantum expires, context switch occurs (process appear to run concurrently).  Timer interrupts used by Linux to measure process quantum.  Quantum Linux 2.4: 210ms, Linux 2.6: 100ms. Linux dynamically changes process priority.  Priority Value = Threshold priority + Nice Value + (Recent CPU usage / 2)  Priority adjusted higher for releasing CPU before quantum (I/O- bound process).  Priority adjusted lower for using entire quantum (CPU-bound process).

5 SILICON VALLEY UNIVERSITY CONFIDENTIAL 5 Summer 2015 Introduction UNIX/Linux Course  Processes  Scheduling Algorithm  Epoch is division of CPU time or a period of time  Every process has a maximum time quantum computed at beginning of each epoch.  When process waiting for I/O its quantum suspended and can be used again in the epoch until its fully used.  Epoch ends when all runnable processes have used all of their quantum Process_3 Quantum_3 epoch Process_2 Quantum_2 Process_1 Quantum_1 Process_3 Quantum_3 Process_1 Quantum_1 Process_1 Quantum_1

6 SILICON VALLEY UNIVERSITY CONFIDENTIAL 6 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Processes  UNIX Process States Process can be in one of many states (Ready, Swapped, Running, Waiting, Zombie). Moves from one state to another. Finishes execution (normally or abnormally) and exists system.

7 SILICON VALLEY UNIVERSITY CONFIDENTIAL 7 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Processes States

8 SILICON VALLEY UNIVERSITY CONFIDENTIAL 8 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Processes  Shell Command Execution Internal (built-in) command has code is part of the shell (i.e. bash) process.  bg, cd, continue, echo, exec, export, fg, pwd, set, umask, wait External command has code in a file (i.e. binary or shell script) found in $PATH.  grep, more, cat, mkdir, rmdir, ls, sort, ftp, telnet, ps fork System Call  UNIX process can create another process by using the fork system call.  Creates an exact memory map of the calling process.  Parent process is the calling process (i.e. shell).  Child process is the created process (i.e. command file). exec System Call  Process overwrite itself with executable code for another command.  Child process uses exec system call to execute shell external command.

9 SILICON VALLEY UNIVERSITY CONFIDENTIAL 9 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Processes  Shell Command Execution

10 SILICON VALLEY UNIVERSITY CONFIDENTIAL 10 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course Processes [student1]$ exec 4<>test_r4 [student1]$ cat >&4 Hello test_r4 Hello test_r4 Hello exit [student1]$ ls -lt test_r4 -rw-rw-r-- 1 student1 student1 39 2013-10-17 15:21 test_r4 [student1]$ cat test_r4 Hello test_r4 Hello test_r4 Hello exit [student1]$ exec: Execute in place of the current shell (instead of creating a new process).

11 SILICON VALLEY UNIVERSITY CONFIDENTIAL 11 Summer 2015 Introduction UNIX/Linux Course  Processes int main() { … pid_t pID = fork(); If (pID == 0) { sIdent = “Child Process: “; … } else if (pID < 0) { /* Failed to fork. */ exit(1); } else { sident = “Parent Process:”;... wait (&status); } … } fork: Spawn a new child process which is an identical process to the parent, except that it has a new system process ID. The process is copied in memory from the parent. - Copy-on-write memory pages created. - Duplicate parent’s page tables. - Create unique task_struct for the child. - Return value = 0 indicates child’s process. child PID in the parent’s process. -1 error, no child process created.

12 SILICON VALLEY UNIVERSITY CONFIDENTIAL 12 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Processes  Shell Command Execution Shell script: a series of shell commands in a file Execution of a shell script is different from execution of an external binary command Execution of a shell script:  The current shell creates a child shell and lets the child shell execute commands in the shell script, one by one.  The child shell creates a child for every command it executes  While the child shell is executing commands in the script file, the parent shell waits for the child to terminate, after which it comes out of waiting state and resumes execution  Only purpose of child shell is to execute commands and eof means no more commands  The child shell is same as parent, unless specified in first line:  # ! /bin/csh

13 SILICON VALLEY UNIVERSITY CONFIDENTIAL 13 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Processes  Shell Command Execution Running another shell: #!/bin/csh

14 SILICON VALLEY UNIVERSITY CONFIDENTIAL 14 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Processes  Shell Command Execution  Subshells ( from current Shell ) Execute commands in another shell. Command line, run the shell (shell becomes the child of the current shell).  sh : Bourne shell  csh : C shell  ksh : Korn shell  bash : Bourne again shell  Commands in Shell Script Child shell has the type of the parent shell. Default, child shell executed by “copy” of parent shell. Change child shell for shell script with “# ! shell-path-name”.  First line of the shell script.  # ! /bin/csh

15 SILICON VALLEY UNIVERSITY CONFIDENTIAL 15 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course Section 8  Processes  Shell Command Execution ps

16 SILICON VALLEY UNIVERSITY CONFIDENTIAL 16 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Processes  Shell Command Execution [student1~]$ cat shell_exe /bin/sh echo Bourne Shell [student1 ~]$./shell_exe sh-3.2$ [student1~]$ ps al F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND... 0 501 9510 9509 15 0 4824 1540 wait Ss pts/4 0:00 -bash 1 501 9542 9510 17 0 4824 740 wait S pts/4 0:00 -bash 0 501 9543 9542 17 0 4816 1352 - S+ pts/4 0:00 /bin/sh [student1~]$ ps axl | grep 9509 F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND 5 501 9509 9507 21 0 8240 1500 - S ? 0:00 sshd: student1@pts/4 0 501 9510 9509 15 0 4824 1540 wait Ss pts/4 0:00 –bash PID of /bin/sh. PPID is default shell when shell script executed. PID of shell when process started from ssh Daemon. PID of ssh Daemon. Same ( the login bash shell). Child shell created when executing shell script.

17 SILICON VALLEY UNIVERSITY CONFIDENTIAL 17 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Processes  Shell Command Execution [student1 ~]$ ps l F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND 0 501 9510 9509 15 0 4824 1540 wait Ss pts/4 0:00 -bash 0 501 9838 9510 17 0 4280 840 - R+ pts/4 0:00 ps l [student1 ~]$ /bin/sh sh-3.2$ ps l F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND 0 501 9510 9509 15 0 4824 1540 wait Ss pts/4 0:00 -bash 0 501 9839 9510 15 0 4816 1404 wait S pts/4 0:00 /bin/sh 0 501 9841 9839 17 0 4280 860 - R+ pts/4 0:00 ps l sh-3.2$ ps axl | grep 9509 5 501 9509 9507 15 0 8240 1504 - S ? 0:00 sshd: student1@pts/4 0 501 9510 9509 15 0 4824 1540 wait Ss pts/4 0:00 -bash 0 501 9848 9839 18 0 4004 712 pipe_w S+ pts/4 0:00 grep 9509 sh-3.2$ Bash shell is waiting for the child process that was created to terminate. Child process uses “exec” command to become the command to be executed. When running shell script, current shell creates child shell to execute commands.

18 SILICON VALLEY UNIVERSITY CONFIDENTIAL 18 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Processes  Attributes : UID, Process Name, PID, Process State, PPID, Process Execution Time.  ps [ options ] Report the process status (attributes of process on system). - a : Display information about processes on terminal session, except local session (i.e. session leader). - e : Display information about all the processes running on the system. - x : List all processes owned. Used with “-a” option, list all processes. - l : Display long list of status report. - u uidlist : Display information about processes belonging to the users with UIDs in the “uidlist” (separated by commas).

19 SILICON VALLEY UNIVERSITY CONFIDENTIAL 19 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Processes  Attributes : $ ps PID TTY TIME CMD 19440 pts/1 0:02 -ksh 18786 pts/1 0:00 ps 20668 pts/1 0:10 vi $ $ ps –a PID TTY TIME CMD 20668 pts/ 10:10 vi 21534 pts/1 0:00 ps $ $ ps -u 147 UID PID TTY TIME CMD 147 18802 pts/1 0:00 ps 147 19440 pts/1 0:02 ksh 147 20668 pts/1 0:10 vi $ $ ps –l F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 200001 A 147 18630 19440 13 66 20 fedf 288 pts/1 0:00 ps 240001 A 147 19440 19496 1 60 20 9e93 476 pts/10:02 ksh ps command (pid=18630) was fork from ksh (pid=19440). Shows process from same pseudo- terminal or ksh process. Display information about processes on terminal session, except local session (i.e. session leader). Display information about UID 147.

20 SILICON VALLEY UNIVERSITY CONFIDENTIAL 20 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Processes  Attributes :  ps - l

21 SILICON VALLEY UNIVERSITY CONFIDENTIAL 21 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Processes  top : Monitor CPU Activity in Real Time  Top version 3.5beta12, Copyright © 1984 through 1996, William LeFebvre A top users display for UNIX These single-character commands are available: ^L —redraw screen q —quit h or ? —help; show this text d —change number of displays to show e —list errors generated by last “kill” or “renice” command i —toggle the displaying of idle processes I —same as ‘i’ k —kill processes; send a signal to a list of processes n or # —change number of processes to display o —specify sort order (size, res, cpu, time) r —renice a process s —change number of seconds to delay between updates u —display processes for only one user (+ selects all users) Displays status of first 15 of most CPU-Intensive tasks on the system, CPU activity, and manipulate processes interactively.

22 SILICON VALLEY UNIVERSITY CONFIDENTIAL 22 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Processes  top : Monitor CPU Activity in Real Time  $ top top - 02:56:55 up 16:17, 3 users, load average: 1.32, 1.92, 2.06 Tasks: 129 total, 2 running, 127 sleeping, 0 stopped, 0 zombie Cpu(s): 2.7%us, 5.4%sy, 0.0%ni, 60.7%id, 30.5%wa, 0.0%hi, 0.7%si, 0.0%st Mem: 1018688k total, 659596k used, 359092k free, 9376k buffers Swap: 2104476k total, 72160k used, 2032316k free, 303896k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1602 root 20 0 70588 29m 3056 S 4.3 2.9 5:14.52 Xorg 4258 sau 20 0 248m 3752 2780 S 1.3 0.4 8:17.84 knotify4...  u top - 03:01:07 up 16:21, 3 users, load average: 0.07, 0.85, 1.57 Tasks: 128 total, 1 running, 127 sleeping, 0 stopped, 0 zombie Cpu(s): 4.7%us, 2.0%sy, 0.0%ni, 92.9%id, 0.0%wa, 0.3%hi, 0.0%si, 0.0%st Mem: 1018688k total, 667048k used, 351640k free, 10144k buffers Swap: 2104476k total, 72156k used, 2032320k free, 314384k cached Which user (blank for all): PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1602 root 20 0 70860 29m 3056 S 3.3 2.9 5:20.79 Xorg 29005 sau 20 0 105m 11m 6576 S 1.3 1.2 0:08.27 konsole ... When top execute, it will take over console until “q” is entered. To change the number of users to display, Enter “u” and top will prompt for users.

23 SILICON VALLEY UNIVERSITY CONFIDENTIAL 23 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  UNIX Responsible for Process and Job Management Process Creation. Process Termination. Running Processes in Foreground.  Process currently controlling Keyboard and Console. Running Processes in Background. Suspending Processes. Switching Processes from Foreground to Background. Switching Processes from Background to Foreground.

24 SILICON VALLEY UNIVERSITY CONFIDENTIAL 24 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process and Job Control  Foreground Process: Syntax: command Executing process keeps control of the keyboard and display screen, until process completes.  Background Process Syntax: command & “&” End of command places command in background. Command takes long time to complete (i.e. find, sort commands). Executing releases the keyboard and display screen to the shell. Local Shell Session can execute multiple background processes in parallel.

25 SILICON VALLEY UNIVERSITY CONFIDENTIAL 25 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process and Job Control  Foreground  fg [ %jobid ] Purpose: Resume execution of the process with job number “jobid” in the foreground or move background processes to the foreground. “%jobid”:  % or %+ (Current job).  % - : Previous job.  %N : Job number N.  %Name : Job beginning with “Name”.  %?Name: Command containing “Name” $ find / -name foo -print > foo.paths 2> /dev/null Command has keyboard and console. Command has prompt..

26 SILICON VALLEY UNIVERSITY CONFIDENTIAL 26 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process and Job Control  Background  bg [ %jobid-list ] Purpose: Resume execution of suspended processes/jobs with job numbers in “jobid-list” in the background. “%jobid”:  % or % + : Current job.  % - : Previous job.  %N : Job Number N.  %Name : Job beginning with “Name”.  %?Name : Command containing “Name”. $ find / -name foo -print > foo.paths 2> /dev/null & [1] 23467 $ [1] = Job Number. 23467 = Process ID (PID). Shell has prompt back to enter next commands.

27 SILICON VALLEY UNIVERSITY CONFIDENTIAL 27 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process and Job Control  jobs [ option ] [ %jobid-list ] Purpose: Display the status of the suspended and background processes in “jobid-list”. If “jobid-list” not defined, display the status of the current job. “%jobid”:  List specified job numbers. - l : Display Process ID (PID) of jobs. [sau@localhost cs206]$ find / -inum 23456 -print > pathnames 2> /dev/null & [1] 2496 [sau@localhost cs206]$ find / -inum 11111 -print > pathnames 2> /dev/null & [2] 2497 [sau@localhost cs206]$ find / -inum 22222 -print > pathnames 2> /dev/null & [3] 2498 [sau@localhost cs206]$ jobs -l [1] 2496 Running find / -inum 23456 -print > pathnames 2> /dev/null & [2]- 2497 Running find / -inum 11111 -print > pathnames 2> /dev/null & [3]+ 2498 Running find / -inum 22222 -print > pathnames 2> /dev/null &

28 SILICON VALLEY UNIVERSITY CONFIDENTIAL 28 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process and Job Control  $ jobs [1] Running find / -inum 23456 -print > pathnames 2> /dev/null & [2]- Running find / -inum 23456 -print > pathnames_2 2> /dev/null & [3]+ Running find / -inum 23456 -print > pathnames_3 2> /dev/null &  $ jobs %?pathnames_2 [2]- Running find / -inum 23456 -print > pathnames_2 2> /dev/null &  $ jobs -l [1] 28337 Running find / -inum 23456 -print > pathnames 2> /dev/null & [2]- 28483 Running find / -inum 23456 -print > pathnames_2 2> /dev/null & [3]+ 28509 Running find / -inum 23456 -print > pathnames_3 2> /dev/null &  $ fg %1 find / -inum 23456 -print > pathnames 2> /dev/null ^C  $ jobs [2]- Running find / -inum 23456 -print > pathnames_2 2> /dev/null & [3]+ Running find / -inum 23456 -print > pathnames_3 2> /dev/null & “Jobs” shows background jobs running. “+” is current job. “-” is the previous job. Bring Job 1 to foregound. Once in foreground, locks the keyboard. terminates process.. suspends process.

29 SILICON VALLEY UNIVERSITY CONFIDENTIAL 29 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process and Job Control  $ fg %2 find / -inum 23456 -print > pathnames_2 2> /dev/null ^Z  $ jobs [2]+ Stopped find / -inum 23456 -print > pathnames_2 2> /dev/null [3]- Running find / -inum 23456 -print > pathnames_3 2> /dev/null &  $ fg %3 find / -inum 23456 -print > pathnames_3 2> /dev/null ^Z [3]+ Stopped find / -inum 23456 -print > pathnames_3 2> /dev/null  $ jobs [2]- Stopped find / -inum 23456 -print > pathnames_2 2> /dev/null [3]+ Stopped find / -inum 23456 -print > pathnames_3 2> /dev/null Bring Job 2 to foreground. Once inforeground, locks the keyboard. suspends process. Job 2 suspended. Bring Job 3 to foreground. suspends process.

30 SILICON VALLEY UNIVERSITY CONFIDENTIAL 30 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process and Job Control  Daemons System Process running in the background. Starts during system initialization or starts when needed and terminates. Offers services to users and handle system administration tasks.  Printer Daemon, lpd: Print spooling system.  finger Daemon, fingerd: Information on logged-in users of system.  ssh Daemon, sshd: Secure remote login server.  udev Daemon, udevd: Dynamic device naming server.  Internet Daemon, xinetd:Server starts other servers providing services over the network (i.e. tftpd). [root@localhost cs206]# ps aux | grep "d$“... root 491 0.0 0.0 2800 1072 ? S<s 03:39 0:00 /sbin/udevd -d root 1432 0.0 0.0 6576 1064 ? Ss 03:39 0:00 /usr/sbin/sshd root 2903 0.0 0.0 4072 856 ? Ss 05:36 0:00 xinetd -stayalive -pidfile /var/run/xinetd.pid

31 SILICON VALLEY UNIVERSITY CONFIDENTIAL 31 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process and Job Control  Sequential Execution of Commands  cmd1; cmd2; …; cmdN Purpose: Execute the “cmd1”, “cmd2”, …, “cmdN” commands sequentially. “;” is command separator. $ date; echo Hello World; uname; who Wed Nov 7 03:18:13 PST 2012 Hello World Linux sau :0 2012-11-05 10:40 (console) sau pts/0 2012-11-05 10:41 sau pts/6 2012-11-06 22:59 uname Hello World date who

32 SILICON VALLEY UNIVERSITY CONFIDENTIAL 32 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process and Job Control  Parallel Execution of Commands  cmd1& cmd2& … cmdN& Purpose: Execute the “cmd1”, “cmd2”, …, “cmdN” in parallel as separate processes. $ date& echo Hello, World& uname; who [4] 5924 [5] 5925 Hello, World Wed Nov 7 03:05:42 PST 2012 Linux [4] Done date [5] Done echo Hello, World sau :0 2012-11-05 10:40 (console) sau pts/0 2012-11-05 10:41 sau pts/6 2012-11-06 22:59 who uname date Hello World

33 SILICON VALLEY UNIVERSITY CONFIDENTIAL 33 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process and Job Control  Sequential and Parallel Execution of Commands $ date& who; whoami; uname; echo Hello World& [4] 7124 sau :0 2012-11-05 10:40 (console) sau pts/0 2012-11-05 10:41 sau pts/6 2012-11-06 22:59 Wed Nov 7 03:32:20 PST 2012 sau [4] Done date Linux [4] 7128 Hello World [4] Done echo Hello World who date whoami uname Hello World Two processes separated by “&”.

34 SILICON VALLEY UNIVERSITY CONFIDENTIAL 34 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process and Job Control  Group Commands  ( cmd1; cmd2; …; cmdN ) Purpose: Execute commands “cmd1”, “cmd2”, …, “cmdN” sequentially, but as one process. $ (date; echo Hello, World); uname; who Wed Nov 7 03:57:53 PST 2012 Hello, World Linux sau :0 2012-11-05 10:40 (console) sau pts/0 2012-11-05 10:41 sau pts/6 2012-11-06 22:59 uname Hello World date who “date” and “echo” executes sequentially, but as one process.

35 SILICON VALLEY UNIVERSITY CONFIDENTIAL 35 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process and Job Control  Group Commands $ (date; echo Hello, World)& (who; uname)& whoami [4] 8544 [5] 8545 sau :0 2012-11-05 10:40 (console) sau pts/0 2012-11-05 10:41 sau pts/6 2012-11-06 22:59 sau Linux Wed Nov 7 04:03:36 PST 2012 Hello, World [4] Done ( date; echo Hello, World ) [5] Done ( who; uname ) $ Hello, World date uname who “date” and “echo” executes sequentially, but as one process. “who” and “uname” executes sequentially, but as one process. whoami

36 SILICON VALLEY UNIVERSITY CONFIDENTIAL 36 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process Termination  Normal Successful Process Termination  Abnormal Process Termination: Foreground Process . Background Process  Use “kill” command.  Use “fg” to bring process into foreground and then use. Primary purpose of “kill” command is to send a signal, a software interrupt, to a process. Process actions upon receiving a signal:  Accept the default action (terminate the process).  Ignore the signal.  Intercept the signal and take an user-defined action. Internal signal ( trap) caused by event internal to the process. External signal caused by event external to the process.

37 SILICON VALLEY UNIVERSITY CONFIDENTIAL 37 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process Termination  Abnormal Process Termination: Internal signal ( trap):  Process executes invalid instruction.  Process access invalid memory address (i.e. NULL dereference, memory reference outside user space). External signal:   Logging off.  “kill” command. kill [ - signal_number ] proc-list  Send the signal for “signal-number” to processes with PIDs in “proc-list”.  - 1 : Hangup or Log out.  - 2 : Interrupt  - 3 : Quit (<Ctrl-\)  - 9 : Sure kill.  - 15 : Software signal (default signal number, i.e. kill ).

38 SILICON VALLEY UNIVERSITY CONFIDENTIAL 38 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process Termination  Abnormal Process Termination: kill [ - signal_number ] proc-list List all signals and the signal names. $ kill –l $ kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV12) SIGUSR213) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGSTKFLT17) SIGCHLD18) SIGCONT19) SIGSTOP 20) SIGTSTP 21) SIGTTIN22) SIGTTOU23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM27) SIGPROF28) SIGWINCH29) SIGIO 30) SIGPWR 31) SIGSYS34) SIGRTMIN35) SIGRTMIN+136) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+439) SIGRTMIN+540) SIGRTMIN+641) SIGRTMIN+7 42) SIGRTMIN+8 43) SIGRTMIN+944) SIGRTMIN+1045) SIGRTMIN+1146) SIGRTMIN+12 47) SIGRTMIN+13 48) SIGRTMIN+1449) SIGRTMIN+1550) SIGRTMAX-1451) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-1154) SIGRTMAX-1055) SIGRTMAX-956) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-659) SIGRTMAX-560) SIGRTMAX-461) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-164) SIGRTMAX

39 SILICON VALLEY UNIVERSITY CONFIDENTIAL 39 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process Termination  Abnormal Process Termination $ ps PID TTY TIME CMD 13495 pts/0 0:03 -ksh 13583 pts/0 9:11 find / -inum 23456 -print 13586 pts/0 5:03 find / -name foo -print 13587 pts/0 23:11 find / -name foobar -print 20577 pts/0 31:07 a.out 20581 pts/0 12:53 sort bigfile > bigfile.sorted $ kill 13583 20577 [1] + Killed find / -inum 23456 -print & $ kill -2 13587 20577 [3] + Killed find / -name foobar -print & $ kill -9 20577 [4] - Killed a.out & $ Default Signal 15 sent to PID 13583. Signal 2 sent to PID 13587. Signal 9 sent to PID 20577. PID 20577 ignores Signals 15 and 2.

40 SILICON VALLEY UNIVERSITY CONFIDENTIAL 40 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process Termination  Logout all processes running in your session get a Hangup Signal and terminates (Default Action).  nohup command [ args ] Purpose: Run “command” and ignore hangup signal (1). Used when a process executes for a long time and do not want to log out (Signal 1) to terminate the process. nohup process should run in background. Logout: Process will ignore the Hangup Signal. Run multiple nohup processes. $ nohup find / -name foo –print 1> foo.paths 2> /dev/null & [1] 15928 $ nohup GenData > employees ; sort employees > sorted & [2] 15931

41 SILICON VALLEY UNIVERSITY CONFIDENTIAL 41 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process Hierarchy in UNIX  init Process: Initial process which starts other processes from the Linux configuration file. Has a PID of 1. Starts up Getty Process for every terminal.  Getty Process: Starts up on active terminal and starts Login Process.  Login Process: Child process fork from the Getty Process and checks validity of the login name and password.  Swapper Process: Starts up the Init Process, scheduler function, and becomes the Idle Process.  UNIX ptree command displays the process tree of the currently running processes on the system showing parent-child relationship.

42 SILICON VALLEY UNIVERSITY CONFIDENTIAL 42 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process Hierarchy in UNIX Init Process exists during lifetime of the system. Getty Process exists as long as the terminal is attached to the system. Shell Process exists as long as user is logged in. Command Process exists as long as command executes.

43 SILICON VALLEY UNIVERSITY CONFIDENTIAL 43 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process Hierarchy in UNIX  Ptree displays the process tree of currently system, showing parent-child relationship. Shell process is bash shell. Init process granddaddy of all processes. Process tree of current system. Telnet session opened.

44 SILICON VALLEY UNIVERSITY CONFIDENTIAL 44 Copyright @2005 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process Hierarchy in LINUX  View process tree using ps command and “f” option (forest).  [student1 ~]$ ps axlf F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND... 5 0 2096 1 18 0 5380 844 - Ss ? 0:00 /usr/sbin/sshd 4 0 2993 2096 17 0 8236 2748 - Ss ? 0:00 \_ sshd: student1 [priv] 5 501 2995 2993 15 0 8236 1512 - S ? 0:00 \_ sshd: student1@pts/3 0 501 2996 2995 16 0 4824 1544 wait Ss pts/3 0:00 \_ -bash 0 501 3028 2996 18 0 4244 852 - R+ pts/3 0:00 \_ ps axlf...  View process tree using pstree. Displays the process tree of currently system, showing parent-child relationship.  [student1 ~]$ pstree init─┬─... ├─sshd───sshd───sshd───bash───pstree...


Download ppt "SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to UNIX / Linux - 8 Dr. Jerry Shiao, Silicon Valley University."

Similar presentations


Ads by Google