2. PRAYER
Heavenly father we pray in Jesus’s name first to thank
you in advance for blessing our families near and far. I
ask that you continue to guide and teach me in all that I say
and do, and that I may do all according to your will. I ask
you to continue to pour our your bountiful blessings and
mercy on myself and my whole family. We thank you for
our health and our strong growing relationship in the
lord.
Amen.
3. INSTRUCTION FOR TODAY
• YOU CAN OPEN YOUR TERMUX OR UBUNTU TERMINAL
• TRY TO USE SOME OF THE COMMAND THAT I WILL SHOW ON THE SCREEN IN
OUR DEEP LEARNING.
• TAKE A SCREEN SHOT FOR THE OUTPUT THAT YOU WILL GET IN EVERY
COMMAND YOU PRACTICE RIGHT NOW.
• THIS IS SERVED AS YOUR SEATWORK ACTIVITY DURING OUR DEEP LEARNING
ACTIVITY.
4. Processes in Linux
A program/command when executed, a special instance is provided by the system to
the process. This instance consists of all the services/resources that may be utilized by
the process under execution.
Whenever a command is issued in unix/linux, it creates/starts a new process. For
example, pwd when issued which is used to list the current directory location the
user is in, a process starts.
Through a 5 digit ID number unix/linux keeps account of the processes, this
number is call process id or pid. Each process in the system has a unique pid.
Used up pid’s can be used in again for a newer process since all the possible
combinations are used.
At any point of time, no two processes with the same pid exist in the system
because it is the pid that Unix uses to track each process.
5. Initializing a process
A process can be run in two ways:
1.Foreground Process : Every process when started runs in foreground by
default, receives input from the keyboard and sends output to the screen.
When issuing pwd command
$ ls pwd
When a command/process is running in the foreground and is taking a lot
of time, no other processes can be run or started because the prompt
would not be available until the program finishes processing and comes
out.
6. Background Process : It runs in the background without keyboard
input and waits till keyboard input is required. Thus, other processes
can be done in parallel with the process running in background since
they do not have to wait for the previous process to be completed.
Adding & along with the command starts it as a background process
$ pwd &
Since pwd does not wants any input from the keyboard, it goes to the
stop state until moved to the foreground and given any data input. Thus,
on pressing Enter, :
Output:
[1] + Done pwd $
7. That first line contains information about the background process – the
job number and the process ID. It tells you that the ls command
background process finishes successfully. The se The second is a
prompt for another command.
Tracking ongoing processes
ps (Process status) can be used to see/list all the running
processes.
$ ps PID TTY TIME CMD 19 pts/1
00:00:00 sh 24 pts/1 00:00:00 ps
8. For more information -f (full) can be used along with
ps
$ ps –f UID PID PPID C STIME TTY TIME CMD 52471 19 1 0 07:20 pts/1
00:00:00f sh 52471 25 19 0 08:04 pts/1 00:00:00 ps -f
For a single process information, ps along with process id is used
$ ps 19 PID TTY TIME CMD 19 pts/1 00:00:00 sh
9. For a running program (named process) Pidof finds the
process id’s (pids)
Fields described by ps are described as:
UID: User ID that this process belongs to (the person running
it)
PID: Process ID
PPID: Parent process ID (the ID of the process that started it)
C: CPU utilization of process
STIME: Process start time
TTY: Terminal type associated with the process
TIME: CPU time taken by the process
CMD: The command that started this process
$ ps PID TTY TIME CMD 19 pts/1
00:00:00 sh 24 pts/1 00:00:00 ps
10. There are other options which can be used along with ps
command :
-a: Shows information about all users
-x: Shows information about processes without terminals
-u: Shows additional information like -f option
-e: Displays extended information
11. Stopping a process
When running in foreground, hitting Ctrl + c (interrupt character) will exit
the command. For processes running in background kill command can be
used if it’s pid is known.
12. If a process ignores a regular kill command, you can use kill -9 followed by
the process ID .
13. Other process commands:
bg: A job control command that resumes suspended jobs while keeping
them running in the background
bg %19
19. Because Linux is a multi-user system, meaning different users
can be running various programs on the system, each running
instance of a program must be identified uniquely by the kernel.
And a program is identified by its process ID (PID) as well as it’s
parent processes ID (PPID), therefore processes can further be
categorized into:
•Parent processes – these are processes that create other
processes during run-time.
•Child processes – these processes are created by other
processes during run-time.
20. The Init Process
Init process is the mother (parent) of all processes on the system, it’s the
first program that is executed when the Linux system boots up; it manages
all other processes on the system. It is started by the kernel itself, so in
principle it does not have a parent process.
The init process always has process ID of 1. It functions as an adoptive
parent for all orphaned processes.
You can use the pidof command to find the ID of a process:
21.
22. Starting a Process in Linux
Once you run a command or program (for example cloudcmd –
CloudCommander), it will start a process in the system. You can start a
foreground (interactive) process as follows, it will be connected to the
terminal and a user can send input it:
23. Linux Background Jobs
To start a process in the background (non-interactive), use the & symbol, here,
the process doesn’t read input from a user until it’s moved to the foreground.
24. You can also send a process to the background by suspending it
using [Ctrl + Z], this will send the SIGSTOP signal to the process,
thus stopping its operations; it becomes idle:
25.
26. States of a Process in Linux
During execution, a process changes from one state to another
depending on its environment/circumstances. In Linux, a process has
the following possible states:
•Running – here it’s either running (it is the current process in the
system) or it’s ready to run (it’s waiting to be assigned to one of the
CPUs).
•Waiting – in this state, a process is waiting for an event to occur or for
a system resource. Additionally, the kernel also differentiates between
two types of waiting processes; interruptible waiting processes – can be
interrupted by signals and uninterruptible waiting processes – are
waiting directly on hardware conditions and cannot be interrupted by
any event/signal.
•Stopped – in this state, a process has been stopped, usually by
receiving a signal. For instance, a process that is being debugged.
•Zombie – here, a process is dead, it has been halted but it’s still has
an entry in the process table.
27. How to View Active Processes in Linux
There are several Linux tools for viewing/listing running processes on
the system, the two traditional and well known
are ps and top commands:
1. ps Command
It displays information about a selection of the active processes on the
system as shown below:
28. 2. top – System Monitoring Tool
top is a powerful tool that offers you a dynamic real-time view of a
running system as shown in the screenshot below:
29. 3. glances – System Monitoring Tool
glances is a relatively new system monitoring tool with
advanced features:
32. 1. Display of Top Command
In this example, it will show information
like tasks, memory, cpu and swap. Press ‘q‘ to quit window.
33. 2. Sorting with -O (Uppercase Letter ‘O’).
Press (Shift+O) to Sort field via field letter, for example press ‘a‘ letter to
sort process with PID (Process ID).
34. Type any key to return to main top window with
sorted PID order as shown in below screen. Press
‘q‘ to quit exit the window.
35. 3. Display Specific User Process
Use top command with ‘u‘ option will display specific User process
details.
36. 4. Highlight Running Process in Top
Press ‘z‘ option in running top command will display running process in color
which may help you to identified running process easily.
37. 5. Shows Absolute Path of Processes
Press ‘c‘ option in running top command, it will display
absolute path of running process.
38. 6. Change Delay or Set ‘Screen Refresh Interval’ in Top
By default screen refresh interval is 3.0 seconds, same can be change pressing
‘d‘ option in running top command and change it as desired as shown below.
39. 7. Kill running process with argument ‘k’
You can kill a process after finding PID of process by pressing ‘k‘ option in
running top command without exiting from top window as shown below.
40. 8. Sort by CPU Utilisation
Press (Shift+P) to sort processes as
per CPU utilization. See screenshot below.
41. 9. Renice a Process
You can use ‘r‘ option to change the priority of the process also called
Renice.
42. 10. Save Top Command Results
To save the running top command results output to a file /root/.toprc use
the following command.
43. 11. Getting Top Command Help
Press ‘h‘ option to obtain the top command help.
45. 13 BASIC CAT COMMAND
• The cat (short for “concatenate“) command is one of the most frequently
used command in linux/unix like operating systems. Cat command allows
us to create single or multiple files, view contain of file, concatenate files
and redirect output in terminal or files. In this article, we are going to find
out handy use of cat commands with their examples in linux.
46. General Syntax
cat [OPTION] [FILE]...
1. Display Contents of File
In the below example, it will show contents of /etc/passwd file.
# cat /etc/passwd root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
narad:x:500:500::/home/narad:/bin/bash
2. View Contents of Multiple Files in terminal
In below example, it will display contents of test and test1 file in terminal.
# cat test test1 Hello everybody Hi world,
47. 3. Create a File with Cat Command
We will create a file called test2 file with below command.
# cat >test2
Awaits input from user, type desired text and press CTRL+D (hold down Ctrl Key and type ‘d‘) to exit.
The text will be written in test2 file. You can see content of file with following cat command.
# cat test2 hello everyone, how do you do?
4. Use Cat Command with More & Less Options
If file having large number of content that won’t fit in output terminal and screen scrolls up very fast, we
can use parameters more and less with cat command as show above.
# cat song.txt | more # cat song.txt | less
48. 5. Display Line Numbers in File
With -n option you could see the line numbers of a file song.txt in the
output terminal.
# cat -n song.txt
1 "Heal The World"
2 There's A Place In
3 Your Heart
4 And I Know That It Is Love
5 And This Place Could
6 Be Much
7 Brighter Than Tomorrow
8 And If You Really Try
9 You'll Find There's No Need
10 To Cry 11 In This Place You’
ll Feel
12 There's No Hurt Or Sorrow