2. Process:-
Process can be defined as a program under Execution . Unix runs many programs
at the Same time by using Round-robin Scheduling algorithm
Shell creates a process for executing the cat command.
The shell process(sh) is a parent process and the cat process is a child process . As
long as process is Running , it is alive. After completing the job , it be comes in
active and is said to be dead.
Parent and child process:-
In Unix one process can generate another process.The process which generates
another process is Called Parent process. Newly generated process is called
child process.
The parent can have one or more children
Eg:-$cat fruits|grep orange fruits
The shell creates two child process cat and grep simultaneously.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
3. Unix process creation:-
★ Parent is the original process.
★new process is called child.
★child cantains same code , same data of its parent.
★the parent can either wait for child to complete , or continue executing in
parallel with the child.
★child is created by system call fork().
★fork()returns 0(zero)in child process.
★fork()returns PID of new child in parent process.
★fork()system call is not successful , it returns-1.
★Resource sharing: a process needs certain resource like CPU time , Memory, I/O
devices etc.
★exec()system call is used after fork(),to start another different program.
★ps command is used display a listing of currently active processes in the system.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
4. A process means program in execution. It generally takes an input, processes
it and gives us the appropriate output. Check Introduction to Process
Management for more details about a process.
There are basically 2 types of processes.
Foreground processes: Such kind of processes are also known as interactive
processes. These are the processes which are to be executed or initiated by the
user or the programmer, they can not be initialized by system services. Such
processes take input from the user and return the output. While these
processes are running we can not directly initiate a new process from the same
terminal.
Background processes: Such kind of processes are also known as non
interactive processes. These are the processes that are to be executed or
initiated by the system itself or by users, though they can even be managed by
users. These processes have a unique PID or process if assigned to them and we
can initiate other processes within the same terminal from which they are
initiated.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
5. Process States in UNIX:
The lifetime of a process can be conceptually divided into 9 states.
1. User Running: The process is executing in user-mode.
2. Kernel Running: The process is executing in the kernel-mode.
3. Ready to run: The process isn’t executing, but it is ready to run as soon as the
kernel schedules it.
4. Asleep: The process is sleeping and resides in the main memory.
5. Ready to run, Swapped: The process is ready to run, but the swapper must
swap the process into the main memory before the kernel can schedule it to
execute.
6. Sleeping, Swapped: The process is sleeping, and the swapper has swapped the
process to secondary storage to make room for other processes in the main
memory.
7. Preempted: The process is returning from the kernel to user mode but the
kernel preempts it and it does a context switch to schedule another process.
8. Created: The process is newly created and not yet ready to run.
9. Zombie: The process no longer exists, but it leaves a record for its parent
process to collect.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
6. Parent and Child Processes
Each unix process has two ID numbers assigned to it: The Process ID (pid) and
the Parent process ID (ppid). Each user process in the system has a parent
process.
Most of the commands that you run have the shell as their parent. Check the ps
-f example where this command listed both the process ID and the parent
process ID.
Zombie and Orphan Processes
Normally, when a child process is killed, the parent process is updated via
a SIGCHLD signal. Then the parent can do some other task or restart a new
child as needed. However, sometimes the parent process is killed before its
child is killed. In this case, the "parent of all processes," the init process,
becomes the new PPID (parent process ID). In some cases, these processes are
called orphan processes.
When a process is killed, a ps listing may still show the process with a Z state.
This is a zombie or defunct process. The process is dead and not being used.
These processes are different from the orphan processes. They have completed
execution but still find an entry in the process table.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
7. Daemon Processes
Daemons are system-related background processes that often run with the
permissions of root and services requests from other processes.
A daemon has no controlling terminal. It cannot open /dev/tty. If you do a "ps
-ef" and look at the tty field, all daemons will have a ? for the tty.
To be precise, a daemon is a process that runs in the background, usually
waiting for something to happen that it is capable of working with. For
example, a printer daemon waiting for print commands.
If you have a program that calls for lengthy processing, then it’s worth to make
it a daemon and run it in the background.
The top Command
The top command is a very useful tool for quickly showing processes sorted by
various criteria.
It is an interactive diagnostic tool that updates frequently and shows
information about physical and virtual memory, CPU usage, load averages, and
your busy processes.
Here is the simple syntax to run top command and to see the statistics of CPU
utilization by different processes −$top
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
8. Job ID Versus Process ID
Background and suspended processes are usually manipulated via job number
(job ID). This number is different from the process ID and is used because it is
shorter.
In addition, a job can consist of multiple processes running in a series or at the
same time, in parallel. Using the job ID is easier than tracking individual
processes.
Nice command:-
It is used to change or set the priority of a process
syntax: $nice-value cat filename
The default priority of a process in unix is 20
The value range from 0 to 39, in linux-9 to 20.where 0 is high and 39 is lower
value.
the default value of reduction is 10.
The priority of a process can be increased only by administrator using double
minus(--).
eg:-$nice--15catlast.txt
The priority of a process can be made lower using the nice command.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
9. For example: if a process is already running and using a lot of cpu time ; then it
can be reniced.
i.e.$nicecatlast.txt
$nice-10catlast.txt
$nice--15catlast.txt
Process Termination:-
There are situations when the user has to terminate a process prematurely. Several
reasons are
Possible for process termination such as:
★The terminal hangs.
★user logs off.
★Program execution has gone into endless loop.
★ Error and fault conditions.
★Time lim
★ Memory unavailable it exceeded.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
10. ★I/O failure.
★Data misuse.
★system performance slow due to too many background processes running.
★Operating system intervention(for example to resolve , adeadlock).When a
UNIX process is terminated normally , it
★Close all files.
★save usage status.
★Makes init process the parent of live children.
★Changes run state to zombie.
Communication commands:-
1)Kill command : Termination of a process forcibly is called killing.
Background process can be terminated by using kill command.
A foreground process is terminated using del key or break key.
PID is used to select the process.
Syntax:-$kill PID.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
11. More than one process can be killed using a single kill
command.
A special variable$!(That holds PID of last background process)
Used to killl last background process.
A special variable $$(That holds PID of current shell)used to kill current shell.
$kill 0:to terminate all process of a user.
$kill -90:to terminate all process of a user including the login shell.
2)mesg command:-is used to change the write permission of a user.
Syntax:-$mesg y #grant the write permission.
$mesg n #denise the write permission.
$mes g #current write status.
If user doesn't want to be disturbed , he can deny the write permission.
But super can send message irrespective of permission.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
12. 3)Write command: allows two way communication between two users
Who are currently logged in and have given write permission.
Syntax:-$write username
The user A can send messages to user B who is logged in.
Then user B get message with a beep sound , then B replies.
But both the users must be logged in.
4)Finger command:-is similar to who command , it shows current login
details and shows asterisk symbol for those who have permission to accept
messages.
Syntax:-$finger
5)wall command:-wall stands for write all. wall command is used only by
the super user to send messages to all users on the system.It is also known as
broadcasting a message to all users , irrespective of there permissions.
Syntax:-$wal
13. Fg
You can use the command “fg” to continue a program which was stopped and
bring it to the foreground.
The simple syntax for this utility is:
e.g:fg jobname
Top
This utility tells the user about all the running processes on the Linux machine.
PS
This command stands for ‘Process Status’. It is similar to the “Task Manager”
that pop-ups in a Windows Machine when we use Cntrl+Alt+Del. This
command is similar to ‘top’ command but the information displayed is
different.
To check all the processes running under a user, use the command –
e.g ps ux
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
14. You can also check the process status of a single process, use the syntax –
ps P
Kill
This command terminates running processes on a Linux machine.
To use these utilities you need to know the PID (process id) of the process you
want to kill
Syntax –kill PID
To find the PID of a process simply type
pidof Process name
DF
This utility reports the free disk space(Hard Disk) on all the file systems.
'df -h'
Free
This command shows the free and used memory (RAM) on the Linux system.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
15. Command Description
bg To send a process to the background
fg To run a stopped process in the foreground
top Details on all Active Processes
ps Give the status of processes running for a user
ps PID Gives the status of a particular process
pidof Gives the Process ID (PID) of a process
kill PID Kills a process
nice Starts a process with a given priority
renice Changes priority of an already running process
df Gives free hard disk space on your system
free Gives free RAM on your system
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune