Difference between revisions of "Linux-Ubuntu/C2/Working-with-Linux-Processes/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "'''TITLE: Working with Linux Processes''' '''Author:''' EduPyramids '''Keywords:''' Process, shell process, PID, PPID, spawning, ps, parent, child, subshell, system process...")
 
(No difference)

Latest revision as of 23:33, 24 January 2026

TITLE: Working with Linux Processes


Author: EduPyramids

Keywords: Process, shell process, PID, PPID, spawning, ps, parent, child, subshell, system process, init


Visual Cue Narration
Slide 1

Title Slide

Welcome to this spoken tutorial on Working with Linux Processes.
Slide 2

Learning Objectives

In this tutorial, we will learn about:
  • Processes in Linux
  • Parent and child processes
  • Process creation and termination
  • Process attributes like PID and PPID
  • The ps command and its options
Slide 3

System Requirements

To record this tutorial, I am using,
Ubuntu OS version 24 point zero 4 
Slide 4

Pre-requisites

https://EduPyramids.org

To follow this tutorial,

Learners should have Ubuntu version 24 point zero 4.

For the prerequisite Linux tutorials please visit this website.

Slide 5

Code Files

The following code file is required to practice this tutorial

  1. wlp-commands.txt

This file is provided in the Code Files link of this tutorial page.

The following code file is required to practice this tutorial.


This file is provided in the Code Files link of this tutorial page.

Slide 6

What is a Process ?

processing.png

Anything running in Linux is called a process.

The shell that accepts commands is a process.

Commands typed in the terminal become processes when executed.

For example, video players, web browsers, and running shell scripts are also processes.

Slide 7

What is a Shell?

Shell1.png

The shell accepts user commands and acts as an interface to the Linux kernel.


It runs commands and shows output.

The kernel starts the shell at login.

The shell creates processes for terminal commands.

Open a terminal.

Press Ctrl + Alt + T keys.

Let us open a terminal.
Highlight to $ sign Here, we can see the command prompt as a dollar sign.

Displaying this prompt is the job of the shell process.

Type date press Enter

Highlight Date.

Highlight Output.

Now let us type date and press Enter.

As soon as we do this, the shell process creates a new process called date.

The shell creates the date process, so it is called the parent process.


The date is called its child process.

After displaying the system date and time, the date process ends.

Slide 8

Spawning

A shell can start another shell as a separate process.

Starting a new process is called spawning a process.

Type sh and press Enter. To spawn another shell process, go to the terminal, type s h, and press Enter.
Highlight $ The original shell, called shell one, creates a child shell.

We can call this child shell as a subshell, or shell two.

Type l s and press enter Let us run the l s command in this new shell.

We see a list of files and directories as output.


At this moment, a new process named ls is created.

Highlight $ of lsHighlight $ of sh Here, Shell 2 is the parent of the l s process.

Shell 1 is the grandparent of the l s process.

The l s process is the child of Shell 2.

At the same time, Shell 2 is the child of Shell 1.

Type exit press Enter.


To terminate Shell 2, type exit and press Enter.

This terminates Shell 2, returning us to the original command prompt of Shell 1.

Now Let’s learn about P I D and P P I Ds
Slide 9

PID and PPID

parent-child.png

Just as a person has a name or ID, each Linux process has its own attributes.

The key process attributes are P I D (Process ID) and P P I D (Parent Process ID).

These details are stored by the Linux kernel in the process table.

PID (Process ID) is a unique number assigned to each process by the kernel.

PPID (Parent Process ID) is the PID of the process that created (spawned) it.

Type: clear and press Enter. Let me clear the terminal screen
Type echo $$

press Enter

point mouse to output PID number.

To see the PID of the current shell, in a terminal type echo space dollar dollar and press Enter.

A number is displayed.

This number is the PID of the current shell.

Type ps press Enter Now type p s, it stands for process status.Press Enter to see the output.

It shows the processes currently running.

A list of all the processes owned by the current user.

hover mouse over CMD column

hover mouse over PID column


hover mouse over TTY column

hover mouse over TIME columnHighlight previous commands output PID number

In the output of the p s command, we can see the following:

Name of the process under the C M D column.

P I D of the process.

TTY shows the terminal or console linked to the process.

TIME shows the total CPU time used by the process.

The P I D of the shell matches the number shown by echo dollar dollar command.

point mouse to PID of bash and output of echo $$ command On my machine, running ps shows two processes:
  • bash, which is the shell itself, and
  • ps, the command we just ran.
type sh press enter Let us see what happens if we spawn a subshell.

Type s h and press Enter.

Type ps press enter

Highlight bash, sh, ps highlight all the PID number.

Now, in the new prompt that appears on the next line, type p s and press Enter.

We can now see three processes:

  • bash the original shell
  • s h the subshell we just spawned
  • p s the command itself

Notice that the bash PID remains the same.The p s command has many options.

type ps -f press Enter

Show the output Highlight bash, sh, and ps -f.

Now type p s space hyphen f and press Enter.

This lists three processes again: bash, s h, and p s hyphen f.

point your mouse to UID, PPID and PID fields The only difference with p s hyphen f is that it shows more process attributes.
  • U I D shows the user who started the process.
  • P P I D shows the P I D of the parent process.
point your mouse to the PID of bash and PPID of sh For example, bash is the parent of the s h subshell.

Therefore, the P I D of bash is the same as the P P I D of s h.

point your mouse to PID of sh and PPID of ps -f

Highlight C column,

The s h process is the parent of the p s command we just ran.

The PID of s h matches the P P I D of p s in the p s hyphen f output.

The C column shows the CPU usage percentage over the process lifetime.

In this example, it is 0 due to minimal CPU usage.

point your mouse to STIME The STIME field shows the time when the process started.

The other fields are the same as those displayed earlier by p s.

Slide 10

Linux Processes

process.png

In Linux processes are of two types:
  1. User processes – These are started by users.

For example, p s or most commands we run in the terminal.

  1. System processes – These are started by the system, often during system startup or user login.

For example, bash is a system process.

To view all processes, including system processes, use the p s command with hyphen e or hyphen A.
type ps -e

Press enter

Go to the terminal and type ps space hyphen e

and press Enter.

We can see a large list of processes.

type

ps -e | more

press Enter

To get a multipage display type ps space hyphen e space vertical bar space more

and press Enter.

Highlight: First line of output:- 1 ? 00:00:08 systemd As seen earlier, the more command shows only the processes that fit in one screen.

Press Enter and scroll through the rest of the process list.The first process in this list is particularly interesting.

It is called the init process.

Almost all other processes are spawned from init, and it always has a P I D of 1.

Press q

Type exit

Press Enter

Highlight the original prompt

Press q to come back to the prompt.


Type exit and press Enter to leave the shell and return to the original prompt.

Slide 11


Summary

In this tutorial, we have learnt about:

  • Processes in Linux
  • Parent and child processes
  • Process creation and termination
  • Process attributes like PID and PPID
  • The ps command and its options
With this we come to the end of this tutorial.

Let us summarise.

Slide 12

As an assignment,

Run the following commands and check the output.

ps -ef

ps -eF

ps -ely

ps -c

As an assignment, please do the following.
Slide 13

Thank you

This Spoken Tutorial is brought to you by EduPyramids Educational Services Private Limited, SINE, IIT Bombay.

Thank you.

Contributors and Content Editors

Madhurig