Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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 a UNIX abstraction that enables to look at the files and programs in another way. A file is treated as a simple file when it lies in a document state on disk. A file can be understood as a process when it is executed.

2 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process The Process Like living organisms processes are born; they give birth to other processes and also die. Processes make things happen in UNIX UNIX is multitasking, hundreds or even thousands of processes can run on a large system.

3 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process The Process Processes belong to the domain of the kernel, which is responsible for their management. We will examine: The Process Attributes Understand the process creation To control these processes by moving them between foreground and background and killing them when they get out of control The process scheduling facilities offered by UNIX

4 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process Process Basics A process is simply an instance of a running program It is said to be born when the program starts execution and remains alive as long as the program is active After execution is complete, the process is said to die A process also has a name, usually the name of the program being executed; for example grep

5 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process Process Basics Even though a process originates from a program, a process can’t be considered synonymous with a program

6 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process Process Basics There are a number of ways that the two can differ First when two users run the same program, there is one program in disk, but two processes in memory Second, when you execute a shell script (also a program) containing a pipeline of three commands, you have three processes Finally, a program can split into two or more processes while it is running

7 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process Process Basics The shell serves the user; but the kernel handles processes Kernel manages memory and schedules processes so that each process has a fair share of the CPU and other resources Kernel provides a mechanism where a process is able to execute for a finite period of time and then relinquish control to another process Kernel saves the state of the process so that when its turn comes up again for execution, the kernel knows where to resume

8 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process Process Basics Process management happens so quickly making the user oblivious to the switching process Files and processes have a lot in common A process is always created by another process, so except for the first process, every process has a parent Processes also are arranged in hierarchical structure with the first process occupying the top; like the root directory of a file system

9 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process Process Basics Just as a directory can have multiple filenames in it, the multitasking nature of UNIX permits a process to have multiple children

10 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process Process Basics Files have attributes and so do processes Attributes are stored in a process table, a separate structure maintained in memory by the Kernel Process table can be referred to as the inode for the processes Process retain an entry in the table until it dies properly (will understand what proper death actually means)

11 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process Process Basics The process table is of finite size, there is a limit to the maximum number of processes that can run on a system Most attributes are inherited by the child from its parent; and there are some attributes that are not inherited and are allocated by the kernel when a process is born: Process Id Parent Process Id

12 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process Process Basics The Process-id (PID) Each process is identified by a unique integer called the Process- id (PID). It is required to control a process, for instance to kill it. The first process has the PID 0. The parent PID (PPID) The PID of the parent is also available in the process table. When several processes have the same PPID, it often makes sense to kill the parent rather than all its children separately

13 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process Process Basics Things can go wrong at times. A process may berserk and multiply rapidly, bringing the system to a complete standstill. However, UNIX provides us with the tools to understand the process hierarchy and control processes

14 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process The Shell and init At the time of login, the process representing the shell starts running at your terminal. This process may be sh, ksh, csh, or bash The shell maintains a set of environment variables, like PATH, and HOME. The shells own pathname is stored in SHELL, but its PID is stored in a special variable, $$. To know the PID of the current shell type $ echo $$ The PID of the login shell does not change as long as you are logged in. When you logout and login again, your login shell will be assigned a different PID.

15 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process The Shell and init The PPID of every login shell is always 1. This is the init process; init is a very important process and, apart from being the parent of users’ shells, it is also responsible for giving birth to every service that’s running in the system—like printing, mail, and so on. Commands like cat and ls run as separate processes. The shell executes a shell script by creating an extra shell process that runs each of the commands in the script. Built in commands of the shell like echo, pwd, and cd don’t create a process at all.

16 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process ps: Displaying Process Attributes The ps (process status) command is used to display some process attributes. ps fetches these attributes from the process table. Compare this to ls which looks up the inode to retrieve a file’s attributes. By default, ps displays the process owned by user invoking the command: {apache:~} ps PID TTY TIME CMD 27589 pts/131 0:00 bash 27489 pts/131 0:00 ksh 28404 pts/131 0:00 ps

17 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process ps: Displaying Process Attributes apache[kkhan:163] bash Querying terminal... Terminal recognized as vt100 (Generic VT100) {apache:~} ps PID TTY TIME CMD 28421 pts/131 0:00 bash 27489 pts/131 0:00 ksh 28426 pts/131 0:00 ps {apache:~} echo $$ 28421 {apache:~} exit exit apache[kkhan:164] echo $$ 27489 apache[kkhan:165]

18 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process ps: Displaying Process Attributes The login shell is ksh and has the PID of 27489. It is running at the terminal /dev/pts/131. The cumulative processer time (TIME) that has been consumed since the process started is negligible. That is to be expected because the shell is mostly sleeping—waiting for a command to be entered and waiting for it to finish. {apache:~} ps PID TTY TIME CMD 27489 pts/131 0:00 ksh 28426 pts/131 0:00 ps apache[kkhan:164] echo $$ 27489

19 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process ps: Displaying Process Attributes ps presents a snapshot of the process table. This picture gets outdated by the time it is displayed. On some systems you might see ps itself in the output. ps is a highly variant command; its actual output varies across different UNIX flavors.

20 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process ps: Displaying Process Attributes Displaying the PPID (-f) since knowing the parenting is often important, the –f option displays a fuller listing that included the PPID: $ ps –f UID PID PPID C STIME TTY TIME CMD kkhan 28714 27489 0 18:04:26 pts/131 0:00 bash kkhan 27489 27487 0 17:46:59 pts/131 0:00 - ksh kkhan 29110 28714 0 18:10:55 pts/131 0:00 ps -f

21 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process ps: Displaying Process Attributes $ps -f UID PID PPID C STIME TTY TIME CMD kkhan 29387 29386 0 18:14:09 pts/131 0:00 ps -f kkhan 28714 27489 0 18:04:26 pts/131 0:00 bash kkhan 27489 27487 0 17:46:59 pts/131 0:00 -ksh kkhan 29385 28714 0 18:14:03 pts/131 0:00 vi guess.sh kkhan 29386 29385 0 18:14:06 pts/131 0:00 /bin/ksh -i

22 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process ps: Displaying Process Attributes ps –u followed by the user-id displays the processes owned by the user-id. The –a option displays process run by all users, irrespective of their ownership. We will discuss (-e and –l) once we have see studied the process creation mechanism.

23 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process ps: Displaying Process Attributes {apache:~/public_html/CS3375} ps -fu kkhan UID PID PPID C STIME TTY TIME CMD kkhan 27487 27448 0 17:46:59 ? 0:00 /usr/lib/ssh/sshd kkhan 28714 27489 0 18:04:26 pts/131 0:00 bash kkhan 27489 27487 0 17:46:59 pts/131 0:00 -ksh kkhan 29623 28714 0 18:19:33 pts/131 0:00 ps -fu kkhan ssh (SSH client) is a program for logging into a remote machine and for executing commands on a remote machine. It provides secure encrypted communications between two un-trusted hosts over an insecure network. sshd (SSH Daemon) is the daemon program for ssh


Download ppt "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."

Similar presentations


Ads by Google