You are on page 1of 27

Process Utilities:

Process: it’s the instance of an executing program

Scheduler: it’s a program running in memory which decides which process should get the cpu

States of processes:

• submit
• hold
• ready
• run
• wait
• complete

When you execute a program the scheduler submits your process to a queue called process queue, at
this instant the process is said to be in submit state.

Once submitted the process waits its turn in the queue and this stage is called hold state.

Process advances in the queue at some instant it would become the next one in the queue to receive
CPU. At this stage its in ready state.

Finally the process gets the CPU and starts getting executed and at this stage its in run state.

When a process requires I/O operation, such processes are put in wait state.

A process whose execution comes to an end goes to complete state and is then removed from the
process queue.

Commands:

1. ps:
to see which processes are running at any instant(displays information about active processes)
or
it report a snapshot of the current processes.
Syntax
Ps [options]
Example:

PID: for every process UNIX assigns a unique number called processID(ranging between 0-
32767)
TTY: Terminal from which the processes were launched
TIME-elapsed time since the processes were launched
CMD: names of the processes
Sh/Bash: Bourne shell which is born the moment you login and dies only when you logout of the
system
Options:
a All users
t Terminal
f Full listing
e Every process running at that
instant
u User
L Nice values will be listed(long
format)
To find out which processes are running for the other users who have logged in execute the ps
command with the option –a.
This command displays processes of all the users.
To see what a particular user is doing
$ps –u Ubuntu
To find out the processes that have been launched from a particular terminal
ps –t tty1

UNIX stores a lot of information about each running process


ps -f
UID-userId
PID-processId
PPID-parent ProcessId
To display every process running at that instant
ps -e(processes which are not in memory)
2. Background processes:
Time consuming tasks can be executed in the background without waiting for the time
consuming task, user can immediately concentrate on another task.
To run a process in the background, &symbol is used while executing a command, if this symbol
is placed at the end of the command then the command will be executed in the background.
Example
$sort employee.dat >emp.out &
17653(process id)

3. The nohup command:


If we are to ensure that the processes that we have executed should not die even when we
logout, the nohup command is used.
nohup-no hang ups
syntax: nohup command
nohup options
Example
nohup sort employee.dat > output.emp
17695
Using this command we can submit the time consuming commands in the background.
4. Killing a process:
Kill is used to terminate a process in the middle of its execution
Ex: cat employee.dat|grep ‘Nagpur’|sort>output.dat&
6173
To kill the process
$ kill 6173
6173 is terminated
Signal is a mechanism to communicate with a process
$kill -9 2316 (9 sure kill signal which specify terminate a process forcibly)
9 Forcibly killing a process
24 Pausing the process
26 Runs a stopped process

Signals
2 Interrupt signal, terminating the
process
1 Hup signal-shutdown and restart
0 Used to check access to the
processid

5. Changing process priorities:


Priority of a process is decided by a number associated with it, this number is called ‘nice’ value
of the process
Nice value ranges from 0-39
Default nice value of a process is 20
$nice cat employee.dat
This increase nice value of cat process from 20 to 30 default ‘10’ will be added as we did not
specify the increment
$nice -15 cat employee.dat
Increment can range from (0-19)
6. At command:
This command is capable of executing UNIX commands at a future date and time.
$tty
/dev/tty3c
$date
Sun nov 7 10:50:00 IST 2021
$at 17:00
Clear > /dev/tty3c
Ctrl+d
Job 803108760.a at Sun nov 7 17:00:00 IST 2021
803108760 specifies job id
.a specifies that a job is created using at command
Sun nov 7 17:00:00 IST 2021-time at which the command submitted using at command will be
executed.
7. Batch Command:
Batch command is used to let the system decide the best time for executing our commands.
System executes the jobs submitted using batch when the load is light
Example
$batch
Sort employee.dat | grep ‘Nagpur’ > addresses.out
ctrl+d
job 692322435.b at Sun nov 7 17:00:00 IST 2021
8. Crontab command:
It can carry out a submitted job everyday for years together
$crontab cmdfile
cmdfile should contain commands which we wish to execute and date & time in a specific
format
format is
Minute Hour DayofMonth MonthofYear DayofWeek Command
$cat > cmdfile
30 10 1 * * echo “ work hard on first day of the month”
0 0 17 11 * mail aa?<confi.letter
Ctrld+d
First command echo’s a message at 10:30 am on first day of every month
Second command mail the contents of the file confi.letter to user aa2 on 17th nov of every year.
Month of year, day of week we use * which specify all possible values
Day of week, Sunday is represented as ‘0’.
Working
$crontab cmdfile
When executed contents of the cmdfile are transferred to the /user/spool/cron/crontabs
directory to a file which has the same name as your login name.
Options
-l : list of submitted jobs
-r : remove the submitted jobs
Backup utilities:
Archive:a set of files are grouped into a single file called archive file

1. tar command:
tar is used to create, maintain, modify and extract files that are archived in the tar format.
Creating an archive using tar command
a) creating an uncompressed tar archive using option cvf
$tar cvf archive-name.tar dirname/

c create a new archive


v List files which are
processed
f Following is the archive
file name

b) create a tar gzipped archive using option cvzf


to use gzip compression on the tar archive use z option
$tar cvzf archive-name.tar.gz dirname/
Note: .tar.gz is same as .tgz
c) Creating a bzipped tar archive using option cvjf
$tar cvfj archive-name.tar.bz2 dirname/

2. Extracting(untar) an archive using tar command


a. Extract a tar file
$tar xvf archive-name.tar
x-extract
b. Extract a gzipped tar archive
$tar xvfz archive-name.tar.gz

c. Extract a bzipped tar archive


$tar xvfj archive-name.tar.bz2
3. Listing an archive using tar command
a. View the tar archive file content without extracting
$tar tvf archive_name.tar

b. View the tar.gz file contents without extracting


$tar tvfz archive-name.tar.gz

c. View the tar.bz2 file content without extracting


$tar tvfj archive-name.tar.bz2
4. Extract a single file from tar, tar.gz, tar.bz2 file
a. $tar xvf archive-file.tar /path/to/file
b. $tar xvcz archive-file.tar.gz /path/to/file
c. $tar xvcj archive-file.tar.bz2 /path/to/file

5. Extract a single directory


6. Adding a file or directory to an existing archive
We cant add file/directory to an compressed archive
7. Estimate the tar archive size
$tar –cf -/directory/to/archive/ |wc –c
20480(kb)

cpio:

cpio stands for copy in and copy out

it can do the following operations

• Copying files to an archive


• Extracting files from an archive
• Passing files to another directory tree

Cpio takes the list of files from the standard input while creating an archive and sends the output to the
standart output

Create *.cpio archive file

$cd objects

$ls

File1.o file2.o file3.o

$ls | cpio –ov >/tmp/object.cpio


Extract *.cpio archive file

$mkdir output

$cd output

$cpio –idv < /tmp/object.cpio

Create *.cpio archive with selected files

$find . –name *.c –print | cpio –ov >/tmp/c-file.cpio


Disk Utilities:

• du
• df
• mount
• unmounts

du:

du estimates and displays the disk space used by files

syntax:

du [option] [file]

options:

a All files and directories


h Human readable form
c Display a grand total
s Summarize
b Bytes

Basic form

$du

Display only directories that are occupying some disk are listed.
Options:

$du –a

Writes counts for all files, not just directories


$du –ah

$du –ahc
$du –sh

$du –achb
df

displays the amount of available disk space on the filesystem

syntax:

df [option] ..[file]

options

a- all filesystems

h- human readable form

--total grand total

-i inodes

-T file system type

Options

$df –a

Displays information of all the filesystems


$df –h

$df –h –total
$df –i(instead of block usage list inodes

$df –T
Mount and Unmount

Mount command mounts a filesystem

Unmounts command unmounts a filesystem

Syntax

mount -t type device dir

mount [-lhv]

mount –a [-f fnrsvw][-t vfstype] [-o optlist]

mount [-fnrsvw][-o option[,option]…] device/dir

mount [-fnrsvw][-t vfstype] [-o options] device/dir

unmount [-hv]

unmount –a [-dfLnrv] [-t vfstype] [-o options]

unmounts [-dfLnrv] {dir/device}


Network Utilities:

1. telnet
telnet program is a user interface to the TELNET protocol ( terminal emulation that enables
a user to connect to a remote host or device using a telnet client).
Syntax: telnet [options] [host[port]]
Options:
-l user – specify user as the user to login as on the remote system
-n tracefile- opens tracefile for recording trace information
Example
$telnet myhost.com
Attempts to open a connection to the remote host myhost.com if a connection is
established, the host will prompt for a login name and password.
$telnet –l myusername myhost.com:5555
Attempts to open a connection to the remote host myhost.com on port 5555 using the login
name myusername
If successful, the host will prompt for myusername’s password.
$telnet
Opens a local telnet prompt
telnet>open myhost.com
will attempt to open a connection to myhost.com
2. rlogin:
remote login to a system
syntax:
rlogin [options] host
options: -l username
example:
rlogin –l hope domain.com
login as user hope to the remote system domain.com

3. ftp
ftp is the user interface to the ARPANET standard file transfer protocol its used to transfer
files to and from a remote network.
Syntax:
ftp [options] [host[port]]
options:
-4 use only ipv4 to contact to host
-6 use only ipv6 to contact to host
-g disables file name globbing
-d enables debugging

$ftp example.ch.com
It attempts a connection to specified host and ask for username and password if connection
establishes
If credentials are right
ftp> prompt opens
ftp > pwd
ftp >ls

You might also like