UNIX Unit-4 Part 1-Process
UNIX Unit-4 Part 1-Process
TOPIC COVERED:
• Introduction to Process
• Initializing the Process
• Terminate or Stopping the Process
• Monitoring and Tracking the Process
• Managing and Controlling the Process
• Booting Process
• Finger Command
INTRODUCTION TO PROCESS
INITIALIZING A PROCESS
For example, if you type pwd, it will immediately show the current
directory (like /home/user), but during that time, the terminal won't
let you type anything else. You must wait until it finishes.
2. Background Process: A background process runs without
blocking the terminal. This means the process runs while you can
still use the terminal for other tasks. To run a command in the
background, you just add an ampersand symbol (&) at the end of
the command.
For example, pwd & will run the same pwd command, but in the
background. Since pwd is a quick command, it finishes almost
instantly and shows a message like [1] + Done pwd, which means
the job is complete. The number [1] is just the job ID, and Done
means it finished.
In Unix or Linux, you can monitor and track the processes running on
your system using the ps command, which stands for process
status. This command shows you information about the programs
and tasks that are currently active.
1. Basic Use:
ps -f
If you know the process ID (PID) of a process and want to see its
details, you can type ps <PID> to get information about that specific
process.
4. Find the PID of a Running Program:
If you want to find out the PID of a running program, you can use the
pidof <program_name> command. For example, pidof firefox will
give you the PID of the Firefox browser if it's running.
There are also several useful options you can combine with the ps
command such as:
In Unix or Linux, you often need to stop or control processes that are
running on your system.
a. In Case of Foreground Process:
For example, if you accidentally start a program that takes too long
or is stuck, pressing Ctrl + C will stop it right away and return you to
the command prompt.
kill 19
In such cases, you can forcefully stop it using a stronger signal. This
is done with:
kill -9 19
Here, the -9 tells the system to send signal 9, also known as SIGKILL,
which forcefully kills the process without giving it a chance to shut
down properly. This is like pulling the plug on a machine it stops
immediately, no matter what.
sleep 10s
This command will make the terminal wait for 10 seconds before you
can use it again.
However, there are times when you might want to run a command
without blocking the terminal. This is where background processes
come into play.
1. Running Commands in the Background or send the foreground
process to the background:
To run a command in the background, you simply add an & at the end
of the command. For example:
Now, instead of waiting for 10 seconds and blocking the terminal, this
command runs in the background. You can use the terminal for other
tasks while sleep 10 is running.
To see all the jobs (commands) that are running in the background,
you can use the jobs command. It will show you a list of all jobs along
with their status. For example:
jobs
Here:
Now, let's say you have a job running in the background, and you
want to bring it back to the foreground to interact with it or wait for it
to finish. You can use the fg command, followed by the job number.
For example:
fg %1
This will bring job 1 (the sleep 10s command) back to the foreground,
and your terminal will be blocked until it finishes.
jobs
bg %1
This will resume job 1 in the background, and you’ll get your terminal
back to do other things
1. top:
The top command is very helpful when you want to monitor system
performance in real-time. When you type top in the terminal, it opens
a live, updating list of running processes, showing useful information
like how much CPU and memory, each process is using. This is great
for spotting programs that are using too many resources or slowing
down your system.
2. nice:
If you want to control how much CPU priority a process gets, you can
use the nice command. This lets you start a new process with a
specific priority level. The syntax is nice -n [value] command, where
the value can be from -20 to 19. A lower value (like -20) means higher
priority (the process gets more CPU time), while a higher value (like
19) means lower priority.
3. renice:
If a process is already running and you want to change its priority later,
you can use the renice command. The syntax is renice [value] -p
[PID], where [PID] is the process ID and [value] is the new priority.
This is useful when a process starts using too many resources and
you want to slow it down without stopping it completely.
BOOTING PROCESS
2. Bootloader Stage:
After the BIOS/UEFI finishes, it looks for a bootloader on the hard
drive (like GRUB – GNU GRUB Bootloader). The bootloader is a
small program that helps load the Linux kernel. It also lets you
choose which operating system to boot if multiple OSes are
installed.
3. Kernel Stage:
The bootloader loads the Linux kernel into memory. The kernel is
the core part of Linux — it controls the system's hardware and
manages all tasks. Once loaded, it initializes the CPU, memory,
input/output devices, and mounts the root filesystem.
FINGER COMMAND
When you type just finger in the terminal, it shows a list of all users
who are currently logged into the system. To do this, it checks a
special system file called utmp, which keeps track of login sessions.
This file tells finger which users are logged in, what terminal they’re
using, and when they logged in. Then, to give more details, finger
investigates another file called /etc/passwd, which stores
information about all users on the system, such as their full name,
home directory, and login shell. If users have optional files like .plan
or .project in their home directories, finger may also show their
contents. This way, the finger command collects and displays both
who is logged in and some basic details about them, making it easy
to know who is using the system at any given time.