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

Slides:



Advertisements
Similar presentations
June 1, 1999Foreground/Background Processing1 Introduction to UNIX H. Foreground/Background Processing.
Advertisements

Week Fourteen Agenda Announcements Final Exam True/False -100 questions (1 point per question) Multiple Choice - 40 questions (2 points per question)
Chapter 5 Controlling Processes Xiaoli Jiao 6/8/99.
Using tcpdump. tcpdump is a powerful tool that allows us to sniff network packets and make some statistical analysis out of those dumps. tcpdump operates.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process The Process A process is.
Chapter 13 Processes. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Objectives To describe the concept of a process, and execution of.
Introduction to Unix – CS 21 Lecture 10. Lecture Overview Midterm questions Jobs and processes description The foreground and background Controlling jobs.
Process Relationships Terminal and Network Logins Process Groups and Sessions Job Control Relationships.
Lesson 10-Controlling User Processes. Overview Managing and processing processes. Managing jobs. Exiting/quitting when jobs have been stopped.
Chapter 13 Processes. What is a process? A process is a program in execution A process is created whenever an external command is executed Whenever the.
Shells and Processes Bryce Boe 2012/08/08 CS32, Summer 2012 B.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Operating Systems Yasir Kiani. 20-Sep Agenda for Today Review of previous lecture Use of FIFOs in a program Example code Process management commands.
CS 497C – Introduction to UNIX Lecture 26: - The Process Chin-Chih Chang
Linux+ Guide to Linux Certification, Second Edition
Process Process: the UNIX abstraction of a stand-along computer that manages resources (memory, CPU, I/O resources) comprising a running program. Processes.
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
Processes & Daemons Chapter IV / Part III. Commands Internal commands: alias, cd, echo, pwd, time External commands, code is in a file: grep, ls, more.
Process Description and Control A process is sometimes called a task, it is a program in execution.
Phones OFF Please Processes Parminder Singh Kang Home:
Process states inWindows 2000 and Linux Module 2.1.
5 UNIX Processes. Introduction  Processes  How to list them  How to terminate them  Process priorities  Scheduling jobs  Signals.
UNIX Processes. The UNIX Process A process is an instance of a program in execution. Created by another parent process as its child. One process can be.
UNIX System Administration Handbook Chapter 4. Controlling Processes 3 rd Edition Evi Nemeth et al. Li Song CMSC691X Summer 2002.
Server Design Discuss Design issues for Servers Review Server Creation in Linux.
Operating Systems Yasir Kiani. 22-Sep Agenda for Today Review of previous lecture Process management commands: bg, fg, ^Z, jobs, ^C, kill Thread.
Introduction to UNIX / Linux - 11
Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.
Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.
The process concept (section 3.1, 3.3 and demos)  Process: An entity capable of requesting and using computer resources (memory, CPU cycles, files, etc).
Linux+ Guide to Linux Certification, Third Edition
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Managing processes and services. 1. How Linux handles processes 2. Managing running processes 3. Scheduling processes.
Linux+ Guide to Linux Certification, Second Edition Chapter 10 Managing Linux Processes.
Lecture – Performance Performance management on UNIX.
The kernel considers each program running on your system to be a process A process lives as it executes, with a lifetime that may be short or long A process.
Week Fourteen Agenda Announcements Final Exam True/False -100 questions (1 point per question) Multiple Choice - 40 questions (2 points per question)
Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork,
System calls for Process management
Scis.regis.edu ● CS 468: Advanced UNIX Class 5 Dr. Jesús Borrego Regis University 1.
Week Fourteen Agenda Announcements Final Exam True/False -100 questions (1 point per question) Multiple Choice - 40 questions (2 points per question)
Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes.
Processes Dr. Yingwu Zhu. Process Concept Process – a program in execution – What is not a process? -- program on a disk - a process is an active object,
Concurrent Processes Processes can concurrently run same program. Processes can concurrently run same program. Processes can start other processes. Processes.
1 Lecture 6 Introduction to Process Management COP 3353 Introduction to UNIX.
UNIX Signals * POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm * Interval Timers * POSIX.1b Timers *
Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.
CIT 140: Introduction to ITSlide #1 CSC 140: Introduction to IT Processes.
1  process  process creation/termination  context  process control block (PCB)  context switch  5-state process model  process scheduling short/medium/long.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 9 Working.
ACCESS CONTROL. Components of a Process  Address space  Set of data structures within the kernel - process’s address space map - current status - execution.
CSC414 “Introduction to UNIX/ Linux” Lecture 3
Agenda Managing Processes (Jobs) Command Grouping Running jobs in background (bg) Bringing jobs to foreground (fg), Background job status (jobs) Suspending.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
Process Relationships Chien-Chung Shen CIS/UD
UNIX signals.
Chapter 13 Processes.
Process Management Process Concept Why only the global variables?
Unix Process Management
Processes A process is a running program.
CHAPTER 8 ( , ) John Carelli, Instructor Kutztown University
Operating Systems Lecture 12.
CHAPTER 13 Processes.
CSC 140: Introduction to IT
Inter-Process Communication ENCE 360
Linux Shell Script Programming
Processes – Part I.
Process Management and System Monitoring
Lecture 6 Introduction to Process Management
Presentation transcript:

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

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

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).

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).

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

SILICON VALLEY UNIVERSITY CONFIDENTIAL 6 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.

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

SILICON VALLEY UNIVERSITY CONFIDENTIAL 8 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.

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

SILICON VALLEY UNIVERSITY CONFIDENTIAL 10 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 student :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).

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.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 12 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

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

SILICON VALLEY UNIVERSITY CONFIDENTIAL 14 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

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

SILICON VALLEY UNIVERSITY CONFIDENTIAL 16 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 wait Ss pts/4 0:00 -bash wait S pts/4 0:00 -bash 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 S ? 0:00 sshd: 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.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 17 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 wait Ss pts/4 0:00 -bash 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 wait Ss pts/4 0:00 -bash wait S pts/4 0:00 /bin/sh R+ pts/4 0:00 ps l sh-3.2$ ps axl | grep S ? 0:00 sshd: wait Ss pts/4 0:00 -bash 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.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 18 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).

SILICON VALLEY UNIVERSITY CONFIDENTIAL 19 Pearson Addison-Wesley Introduction UNIX/Linux Course  Processes  Attributes : $ ps PID TTY TIME CMD pts/1 0:02 -ksh pts/1 0:00 ps pts/1 0:10 vi $ $ ps –a PID TTY TIME CMD pts/ 10:10 vi pts/1 0:00 ps $ $ ps -u 147 UID PID TTY TIME CMD pts/1 0:00 ps pts/1 0:02 ksh pts/1 0:10 vi $ $ ps –l F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD A fedf 288 pts/1 0:00 ps A e 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.

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

SILICON VALLEY UNIVERSITY CONFIDENTIAL 21 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.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 22 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: k total, k used, k free, 9376k buffers Swap: k total, 72160k used, k free, k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1602 root m 3056 S :14.52 Xorg 4258 sau m S :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: k total, k used, k free, 10144k buffers Swap: k total, 72156k used, k free, k cached Which user (blank for all): PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1602 root m 3056 S :20.79 Xorg sau m 11m 6576 S :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.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 23 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.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 24 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.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 25 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..

SILICON VALLEY UNIVERSITY CONFIDENTIAL 26 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] $ [1] = Job Number = Process ID (PID). Shell has prompt back to enter next commands.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 27 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. cs206]$ find / -inum print > pathnames 2> /dev/null & [1] 2496 cs206]$ find / -inum print > pathnames 2> /dev/null & [2] 2497 cs206]$ find / -inum print > pathnames 2> /dev/null & [3] 2498 cs206]$ jobs -l [1] 2496 Running find / -inum print > pathnames 2> /dev/null & [2] Running find / -inum print > pathnames 2> /dev/null & [3] Running find / -inum print > pathnames 2> /dev/null &

SILICON VALLEY UNIVERSITY CONFIDENTIAL 28 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process and Job Control  $ jobs [1] Running find / -inum print > pathnames 2> /dev/null & [2]- Running find / -inum print > pathnames_2 2> /dev/null & [3]+ Running find / -inum print > pathnames_3 2> /dev/null &  $ jobs %?pathnames_2 [2]- Running find / -inum print > pathnames_2 2> /dev/null &  $ jobs -l [1] Running find / -inum print > pathnames 2> /dev/null & [2] Running find / -inum print > pathnames_2 2> /dev/null & [3] Running find / -inum print > pathnames_3 2> /dev/null &  $ fg %1 find / -inum print > pathnames 2> /dev/null ^C  $ jobs [2]- Running find / -inum print > pathnames_2 2> /dev/null & [3]+ Running find / -inum 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.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 29 Pearson Addison-Wesley Introduction UNIX/Linux Course  Process and Job Control  $ fg %2 find / -inum print > pathnames_2 2> /dev/null ^Z  $ jobs [2]+ Stopped find / -inum print > pathnames_2 2> /dev/null [3]- Running find / -inum print > pathnames_3 2> /dev/null &  $ fg %3 find / -inum print > pathnames_3 2> /dev/null ^Z [3]+ Stopped find / -inum print > pathnames_3 2> /dev/null  $ jobs [2]- Stopped find / -inum print > pathnames_2 2> /dev/null [3]+ Stopped find / -inum 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.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 30 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). cs206]# ps aux | grep "d$“... root ? S<s 03:39 0:00 /sbin/udevd -d root ? Ss 03:39 0:00 /usr/sbin/sshd root ? Ss 05:36 0:00 xinetd -stayalive -pidfile /var/run/xinetd.pid

SILICON VALLEY UNIVERSITY CONFIDENTIAL 31 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 : :40 (console) sau pts/ :41 sau pts/ :59 uname Hello World date who

SILICON VALLEY UNIVERSITY CONFIDENTIAL 32 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 : :40 (console) sau pts/ :41 sau pts/ :59 who uname date Hello World

SILICON VALLEY UNIVERSITY CONFIDENTIAL 33 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 : :40 (console) sau pts/ :41 sau pts/ :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 “&”.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 34 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 : :40 (console) sau pts/ :41 sau pts/ :59 uname Hello World date who “date” and “echo” executes sequentially, but as one process.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 35 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 : :40 (console) sau pts/ :41 sau pts/ :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

SILICON VALLEY UNIVERSITY CONFIDENTIAL 36 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.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 37 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 ).

SILICON VALLEY UNIVERSITY CONFIDENTIAL 38 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

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

SILICON VALLEY UNIVERSITY CONFIDENTIAL 40 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] $ nohup GenData > employees ; sort employees > sorted & [2] 15931

SILICON VALLEY UNIVERSITY CONFIDENTIAL 41 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.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 42 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.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 43 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.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 44 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 Ss ? 0:00 /usr/sbin/sshd Ss ? 0:00 \_ sshd: student1 [priv] S ? 0:00 \_ sshd: wait Ss pts/3 0:00 \_ -bash 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...