Linux/C2/Working-with-Linux-Process/English-timed

From Script | Spoken-Tutorial
Revision as of 12:06, 11 March 2015 by Sandhya.np14 (Talk | contribs)

Jump to: navigation, search
Time Narration
00:00 Welcome to this spoken tutorial on Working with Linux Processes.
00:05 I am using Ubuntu 10.04.
00:09 We assume that you know how to get started with the Linux operating system and have some basic idea about commands.
00:16 If you are interested, it is available through another spoken tutorial on the following website. http://spoken-tutorial.org
00:28 Also note that Linux is case sensitive. All the commands used in this tutorial are in lower case unless otherwise mentioned.
00:38 To understand what a process is, let me give you a brief explanation.
00:42 Anything that is running in Linux is a process.
00:46 The shell that is running and taking our commands is a process.
00:51 The commands that we type on the terminal are processes when they are running.
00:56 The video in which you are seeing this tutorial is a process.
01:00 The browser running in which you have opened the spoken tutorial website is a process.
01:05 Shell scripts that are running are processes and so on.
01:11 A process can be defined as a program which is being executed i.e. which is running.
01:17 Processes are much like us. They are born, they die. They have parent and children.
01:28 Let us first learn about the shell process.
01:31 The shell process is started by the Linux kernel as soon as we login to the system.
01:36 At this point it would suffice to know that the 'Linux kernel' is the core of the Linux operating system.
01:43 It consists of the most essential components that makes Linux run. The shell creates or gives birth to all the other user command processes.
01:53 Let us open a terminal.
01:57 We can see the command prompt on the terminal in the form of a dollar sign.
02:03 This is the job of the shell process.
02:07 Now, let us type any command say “date” and press Enter.
02:13 As soon as we do this the shell process will create a process called 'date'.
02:18 Now, since the shell process has given birth to the 'date' process, we can say that the 'shell process' is the parent of the 'date process' and the 'date process' is the child of the 'shell process'.
02:30 Once 'date' process has shown the system date and time, it will die.
02:40 A shell can also give birth to another shell process. Giving birth to a process or creating a process is also called spawning a process.
02:50 To spawn another shell process, simply go to the terminal and type “sh” and press Enter.
03:00 We would see a new prompt appearing in the terminal. Now our original shell, let us call it 'shell 1', has given birth to a child shell or 'sub shell', let us call it 'shell 2'.
03:13 Now you may run a command in the new command prompt as well. Let us run 'ls' command in this new command prompt.
03:20 Now at the command prompt, type “ls” and press Enter. We can see a list of files and directories.
03:32 Now a new process named 'ls' is created.
03:35 Here, 'shell 2' is the parent of 'ls', while 'shell 1' is the grandparent of 'ls'. 'ls' is the child of 'shell 2', while 'shell 2' itself is the child of 'shell 1'.
03:56 To kill 'shell 2', simply type at the new prompt “exit” and press Enter.
04:04 This will kill 'shell 2' and we will get back our original command prompt.
04:12 Continuing our analogy between us and processes, we know that each of us have some attributes that identify us. Those attributes can be our name, parents' name , date of birth, PAN card no. etc.
04:26 Similarly, processes also have attributes like PID(Process ID), PPID(Parent Process ID), Start time, etc.
04:38 Most of these attributes are maintained by the kernel in a process table.
04:43 Each process is uniquely identified by a unique integer called the PID. PID is allotted by the kernel when the process is born.
04:51 The PID of the parent process that spawned a new process say 'P1' is called the PPID of 'P1' process.
05:00 To see the PID of the current shell, at the prompt type “echo space dollar dollar” and press Enter.
05:11 A number would be shown. This is the PID of the current shell.
05:23 The one command that we would use a lot while talking about processes is the ps command.
05:29 ps or process status is a command which displays the processes running in the system.
05:34 Let us see what happens if we run this command without any options.
05:40 Now, at the command prompt type “ps” and press Enter.
05:47 This way we would normally see the list of all the processes owned by the user running the program.
05:54 You can see the name of the process under CMD heading.
05:58 Other than this you can a see the PID, TTY or the console at which the process is running ,the TIME
06:06 that is the total processor time that has been used since the process started.
06:12 On my machine it displays two processes.
06:16 One is bash, the shell process we are using. The other is the 'ps' process itself.
06:25 The other important thing to note here is that the PID of the shell process is same as that shown by the 'echo space dollar dollar' command.
06:35 If we spawn a sub-shell , let us see what happens. At the terminal type “sh” and press Enter.
06:42 Now, in the new prompt that appears on the new line, type “ps” and press Enter.
06:51 Now we can see 3 processes in the list . The process 'sh' has been added.
06:57 Here again notice that the PID of the bash process is same as that before.
07:05 'ps' comes with many options as we would see next. First option that we would see displays more attributes for the processes listed.
07:13 Now type at the prompt “ps space minus f” and press Enter. This again will list three processes as in the previous case.
07:28 Bash, sh and ps -f.
07:31 The only difference is, now more attributes are listed.
7:36 UID gives the user name of the user who has started the process. Also it shows the PPID that is the PID of the parent process that created the process.
07:47 For example, see that 'bash' process is the parent of 'sh' process , so the PID of bash is same as the PPID of 'sh' process.
08:00 Similarly since 'sh' process is the parent of 'ps' process, the PID of 'sh' process is the same as the PPID of the 'ps -f' process.
08:17 'C' stands for processor utilization. Currently, this is the integer value of the percent usage of the processor over the lifetime of the process.
08:26 It will be displayed as 0 in this case as the usage is negligible.
08:32 The 'STIME' field gives the time at which the process started, the rest we have already seen while running 'ps'.
08:42 Processes are of two types : First one is User processes. Those are started by the users.
08:49 For example 'ps' or for that reason most commands that we run on the terminal.
08:54 Second one is system processes. Those processes are started by the system often during system startup or user login.
09:05 Example of system process can be 'bash'.
09:09 Sometimes we may want to see all the processes - both system processes as well as user processes.
09:17 Then we use the 'minus e' or the 'minus capital A' option.
09:23 Go to the terminal and type at the prompt “ps space minus e” and press Enter.
09:32 We can see a large list of processes.
09:35 To get a multipage display just type at the prompt
9:40 “ps space minus e space vertical bar space more” and press Enter.
09:52 As we have seen before, 'more' will cause only as many processes to be listed as can fit in one window.
09:58 As we press Enter, we scroll through the list of processes.
10:03 The first process in this list is interesting. It is called the 'init' process.
10:09 It is the process from which almost all other processes are spawned.
10:12 It has a PID of 1.
10:16 To come back to the prompt press 'q'.
10:24 So, in this tutorial, we have learned about process, shell process, spawning of process, process attributes and different types of processes.
10:37 We also learned the use of 'ps' command. This brings me to the end of this tutorial.
10:45 Spoken Tutorials is a part of the Talk to a Teacher project, supported by the National Mission on Education through ICT, MHRD, Government of India.
10:55 More information on the same is available at the following link

http://spoken-tutorial.org/NMEICT-Intro.

11:07 This script has been contributed by ----------------------(name of the translator) and this is -----------------------(name of the recorder) from --------------------------(name of the place)signing off. Thanks for joining.

Contributors and Content Editors

Minal, PoojaMoolya, Pratik kamble, Sandhya.np14