0% found this document useful (0 votes)
2 views14 pages

UNIX Unit-4 Part 1-Process

This document covers system administration and networking topics, focusing on processes in Unix/Linux systems, including their initialization, monitoring, and management. It explains how to control processes using commands like ps, kill, and top, as well as the booting process of Linux and the use of the finger command for user information. Key concepts include foreground and background processes, process IDs, and various commands for managing system resources.

Uploaded by

almighty.aytul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views14 pages

UNIX Unit-4 Part 1-Process

This document covers system administration and networking topics, focusing on processes in Unix/Linux systems, including their initialization, monitoring, and management. It explains how to control processes using commands like ps, kill, and top, as well as the booting process of Linux and the use of the finger command for user information. Key concepts include foreground and background processes, process IDs, and various commands for managing system resources.

Uploaded by

almighty.aytul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

UNIT :- 4

SYSTEM ADMINISTRATION AND NETWORKING

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

In Linux and Unix-based systems, every program or command that is


executed is treated as a process. A process is a running instance of a
program that is provided with its own memory space and system
resources such as CPU time, file descriptors, and input/output
mechanisms. This execution instance is managed by the operating
system, which assigns various resources necessary for its operation.
• Whenever a command is run in the terminal such as pwd, which
prints the current working directory a new process is created by
the system.
• Each process in Unix/Linux is uniquely identified by a Process ID
(PID), which is a five-digit numerical value. This PID is critical
because it allows the system to keep track of all active processes.
• Since there are a limited number of PIDs available, the system
reuses PIDs once previous processes have completed. However,
at any given moment, no two active processes will share the same
PID.

INITIALIZING A PROCESS

In Unix or Linux, when you run a command, it starts a process. This


process can run in two ways: foreground or background.

1. Foreground Process: By default, every command you type runs as


a foreground process. This means it takes over the terminal, and
you must wait for it to finish before you can type another command.

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.

MONITORING AND TRACKING PROCESSES

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:

For Example, if you simply type ps command in the terminal, it will


display a list of processes that are currently running in your session
or terminal window.
ps

However, this command shows the basic output is limited and


doesn’t show much detail.

2. Getting Detail Information:

To get more detailed information, you can use ps –f command, where


the -f stands for full format. This provides additional fields such as
the UID, which tells you the user ID of the person who started the
process, and the PID, which is the unique process ID assigned by the
system. It also shows the PPID (parent process ID), which tells you
which process started this one. Other useful details include the C
column (CPU usage), STIME (when the process started), TTY (the
terminal the process is running on), TIME (how much CPU time the
process has used), and CMD (the actual command that launched the
process).

ps -f

3. Getting Information of the Specific Process:

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.

5. Other Useful Options:

There are also several useful options you can combine with the ps
command such as:

• -a option shows processes from all users (not just yours).


• -x includes processes that are not connected to a terminal.
• -u shows the output in a user-friendly format.
• -e displays every process running on the system.

By combining these options, you can get a full overview of everything


happening in the system, which is especially helpful for system
monitoring and troubleshooting.

STOPPING OR CONTROLLING THE PROCESS

In Unix or Linux, you often need to stop or control processes that are
running on your system.
a. In Case of Foreground Process:

If a foreground process (one that runs directly in your terminal) needs


to be stopped, the simplest way to do this is by pressing Ctrl + C on
your keyboard. This sends a signal called an interrupt signal to the
process, telling it to stop immediately.

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.

b. In case of Background Process:

However, if the process is running in the background, stopping it is a


bit different. You can't use Ctrl + C for background processes.
Instead, you use the kill command along with the PID (process ID) of
the background process. For instance, if you want to stop a process
with the PID 19, you will type the following command in the terminal:

kill 19

This sends a regular termination signal to the process, asking it to


stop. Most of the time, this works fine. But sometimes, the process
may not respond for example, if it’s stuck or misbehaving.

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.

MANAGING AND CONTROLLING PROCESSES

In Unix or Linux, there are several useful commands for managing


and controlling processes beyond just starting and stopping them.
When you run a command in the terminal, it usually runs in the
foreground, meaning it takes control of the terminal, and you can't
use the terminal for anything else until the command finishes. For
example, if you run a command like this:

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:

sleep 10s &

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.

2. Checking Jobs with jobs:

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

Output might look something like this:

[1] + 12345 Sleep 10s

Here:

• [1] is the job number.


• 12345 is the process ID (PID) of the job.
• Sleep 10s is the command that’s running in the background.

3. Bringing a Job to the Foreground (fg) send the background


process to the foreground:

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.

4. Running a Job in the Background After Stopping It (bg):

Sometimes, you might accidentally stop a job that’s running in the


foreground by pressing Ctrl + Z. This suspends the job temporarily.
You can see the job is stopped using the jobs command. For
example:

jobs

The output might look like this:


[1]+ 12345 Stopped Sleep 10s

To resume this job in the background (so it continues running without


blocking the terminal), use the bg command:

bg %1

This will resume job 1 in the background, and you’ll get your terminal
back to do other things

OTHER USEFUL COMMANDS FOR MANAGING AND


CONTROLLING THE PROCESS:

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.

For example, nice -n 10 myscript.sh runs the script with lower


priority, so it won’t slow down other important tasks.

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

The booting process in Linux is the sequence of steps that happen


when you turn on your computer and the Linux operating system
starts. It begins with the hardware powering up and ends when you
get a usable system with a login screen or terminal.
1. BIOS/UEFI Stage:
When you press the power button, the computer's BIOS (or UEFI in
modern systems) starts. It performs basic checks to make sure
the hardware (CPU, RAM, keyboard, etc.) is working. This is called
the POST (Power-On Self-Test).

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.

4. Init / systemd Stage:


After the kernel is loaded, it starts a process called init (or systemd
on modern Linux systems). This is the first process (PID 1) and is
responsible for starting all other services and processes like
networking, sound, display, and background daemons.

5. Login / Shell Stage:


Finally, the system shows the login prompt or graphical desktop
(GUI). At this point, the Linux system is ready to be used by the user.

FINGER COMMAND

The 'finger' command is a powerful utility in Linux used to display


information about users logged into the system. This command is
commonly used by system administrators to retrieve detailed user
information, including login name, full name, idle time, login time,
and sometimes the user's email address.

How finger process provides the details of all users currently


logged into the UNIX system?

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.

You might also like