Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 140: Introduction to IT

Similar presentations


Presentation on theme: "CSC 140: Introduction to IT"— Presentation transcript:

1 CSC 140: Introduction to IT
Processes CIT 140: Introduction to IT

2 CIT 140: Introduction to IT
Topics What is a process? Process states and multitasking How does the shell execute processes? Foreground and background processes Job control Process tree Process commands CIT 140: Introduction to IT

3 CIT 140: Introduction to IT
A process is a program in execution. A process is created every time you run an external command and is removed after the command finishes its execution. CIT 140: Introduction to IT

4 CIT 140: Introduction to IT
Multitasking Only one process is using a CPU at a time. A process uses the CPU until: It makes an I/O request, or It reaches the end of its time slice, or It is terminated. The technique used to choose the process that gets to use the CPU next is called Process scheduling. CIT 140: Introduction to IT

5 CIT 140: Introduction to IT
Process State As a process executes, it changes state new: The process is being created. running: Instructions are being executed. waiting: The process is waiting for some event to occur. ready: The process is waiting to be assigned to a CPU. terminated: The process has finished execution. zombie: Process has been terminated and is waiting for its resources to be recovered. CIT 140: Introduction to IT

6 CIT 140: Introduction to IT
Process States A UNIX process can be in one of many states, typically ready, running, or waiting. CIT 140: Introduction to IT

7 CIT 140: Introduction to IT
Process Scheduling First come, First serve(FCFS) Process that enters system first is assigned highest priority. Priority Scheduling Assign priorities based on accumulated CPU time. New and I/O bound processes have highest priorities. Round Robin (RR) A process gets to use the CPU for one time slice, then the CPU is given to another process, the next process in the queue of processes waiting to use the CPU. CIT 140: Introduction to IT

8 Execution of shell Commands
A shell command can be external or internal. Internal (built-in) command: is part of the shell: ex: bg, cd, continue, echo, exec External command: separate program or script ex: grep, more, cat, mkdir, rmdir, ls CIT 140: Introduction to IT

9 Execution of shell Commands
A UNIX process is created by the fork() system call, which creates an exact copy of the original process. The forking process is known as the parent process. The created (forked) process is called the child process. CIT 140: Introduction to IT

10 Execution of shell Commands
To execute an external command, the exec() system call is used after fork. exec() replaces the current process in memory with the specified file and begins running it. CIT 140: Introduction to IT

11 Execution of shell Commands
CIT 140: Introduction to IT

12 Execution of Shell Scripts
Shell script: a series of shell commands in a file Execution different from binary programs. Current shell creates a child shell and lets the child shell execute commands in the shell script, one by one. Child shell creates a child process 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. CIT 140: Introduction to IT

13 Execution of shell Commands
CIT 140: Introduction to IT

14 CIT 140: Introduction to IT
Process Attributes Processes have a variety of attributes: User owner Group owner Process name Process ID (PID) Parent process ID (PPID) Process state Length of time running Amount of memory used CIT 140: Introduction to IT

15 CIT 140: Introduction to IT
Process Status ps [options] (System V version) Purpose Report process status Output Attributes of process running on the system Commonly used options/features: -a Display Information about the processes executing on your terminal except the session header (your login shell) -e Display information about all the processes running on the system -f Display full list (8 columns) of status report. -l Display long list (14 columns) of status report. -u uidlist Display information about processes belonging to the users with UIDs in the ‘uidlist’ (UIDs separated by commas) CIT 140: Introduction to IT

16 CIT 140: Introduction to IT
Examples of ps > ps PID TTY TIME CMD 24621 pts/13 0:00 bash 24740 pts/13 0:00 ps > ps -f UID PID PPID C STIME TTY TIME CMD waldenj :51:55 pts/13 0:00 -bash waldenj :55:06 pts/13 0:00 /usr/bin/ps -f > ps -l F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 8 S ? ? pts/13 0:00 bash 8 O ? pts/13 0:00 ps > ps -ef|head root Jun 16 ? :01 sched root Jun 16 ? :39 /etc/init - root Jun 16 ? :01 pageout root Jun 16 ? :56 fsflush root Jun 16 ? :00 /usr/lib/saf/sac -t 300 root Jun 16 ? :00 /usr/lib/snmp/snmpdx -y -c /etc/snmp/conf root Jun 16 ? :05 /usr/sbin/vold root Jun 16 ? :00 /usr/lib/sysevent/syseventd root Jun 16 ? :01 /usr/lib/picl/picld CIT 140: Introduction to IT

17 Process and Job control
Shell manages your processes for you: Process creation Process termination Suspending processes Running foreground processes. Running background processes. Switching processes to foreground/background. CIT 140: Introduction to IT

18 Example of Background Processes
> find / -name foo 2>/dev/null & [1] 25299 > bzip2 bash.man & [2] 25304 > ps PID TTY TIME CMD 24621 pts/13 0:00 bash 25299 pts/13 0:03 find 25305 pts/13 0:00 ps > [2]+ Done bzip2 bash.man CIT 140: Introduction to IT

19 CIT 140: Introduction to IT
Suspending a Process What if you forgot to background a process? Suspend the process with <Ctrl-z> Use fg or bg to unsuspend process. Use stop to suspend background processes. If you don’t have a stop command, use alias stop=“kill –STOP” Example CIT 140: Introduction to IT

20 Managing Background Processes: fg
fg[%jobid] Purpose: Resume execution of the process with job number ‘jobid’ in the foreground or move background processes to the foreground. Commonly used values for ‘%jobid’ % or %+ Curent job %- Previous job %N Job Number N %Name Job beginning with ‘Name’ CIT 140: Introduction to IT

21 Managing Background Processes: bg
bg[%jobid-list] Purpose: Resume execution of suspended processes/jobs with job numbers in ‘jobid-list’ in the background. Commonly used values for ‘%jobid’: % or %+ Curent job %- Previous job %N Job Number N %Name Job beginning with ‘Name’ %?Name Command containing ‘Name’ CIT 140: Introduction to IT

22 CIT 140: Introduction to IT
UNIX Daemons A daemon is a system process running in the background. Most system services are daemons: Printing Ssh Web CIT 140: Introduction to IT

23 Sequential and Parallel Execution
cmd1; cmd2; … ; cmdN Purpose: Execute the ‘cmd1’, ‘cmd2’, ‘cmd3’,…,’cmdN’ commands in sequence. cmd1 & cmd2 & … & cmdN & Purpose: Execute commands ‘cmd1’,cmd2’,…’cmdN’ in parallel as separate processes. CIT 140: Introduction to IT

24 CIT 140: Introduction to IT
Terminating a Process Can terminate a foreground process by <Ctrl-C> Can terminate a background process: Find the PID with ps, then use kill PID. Bring process into foreground with fg, then use <Ctrl-C> CIT 140: Introduction to IT

25 CIT 140: Introduction to IT
Terminating a Process > find / -name foo 2>/dev/null >foo.txt & [4] 28344 > sort bigFile | bzip2 -c >sortFile.bz2 & [5] 28350 > jobs [2]+ Stopped vim smallFile [3] Running sleep & [4] Running find / -name foo 2>/dev/null >foo.txt & [5]- Running sort bigFile | bzip2 -c >sortFile.bz2 & > kill %5 [5]- Terminated sort bigFile | bzip2 -c >sortFile.bz2 > ps PID TT S TIME COMMAND 28022 pts/4 S 0:00 -bash 28132 pts/4 T 0:00 vim smallFile 28137 pts/4 S 0:00 sleep 10000 28344 pts/4 R 0:05 find / -name foo > kill 28344 [4]- Terminated find / -name foo 2>/dev/null >foo.txt CIT 140: Introduction to IT

26 CIT 140: Introduction to IT
Job Numbers vs PIDs PIDs Every process has a PID. PIDs are global (shared by every user.) Job Numbers Every job has a job number. Jobs may contain multiple processes. Job numbers are local (every user has own %1...) CIT 140: Introduction to IT

27 UNIX Process Hierarchy
System starts init process on boot. Init is PID 1. Init starts system processes System daemons. Graphical login: xdm, kdm, gdm Text login: getty -> login Network login: sshd Login runs User shell CIT 140: Introduction to IT

28 Process Hierarchy in UNIX
CIT 140: Introduction to IT


Download ppt "CSC 140: Introduction to IT"

Similar presentations


Ads by Google