Está en la página 1de 26

Linux Based Networks Zahid Shafique, Instructor

Linux Based Networks


Punjab University College of Information Technology

Instructor: Zahid Shafique


<z_shafique@hotmail.com>

Topic Heading Class Meeting # Slide : 1


Linux Based Networks Zahid Shafique, Instructor

Today’s Agenda

Topic Heading Class Meeting # Slide : 2


Linux Based Networks Zahid Shafique, Instructor

Using who to List Users Logged In to the System

To see everyone who's currently logged in to the system, you


can enter who. You then see a display similar to the following:

$ who
root tty01 Jul 25 08:00
user1 tty02 Jul 25 10:37
user2 tty03 Jul 25 11:02
user35 tty05 Jul 25 09:21
zahid ttys7 Jun 25 18:49
$

Topic Heading Class Meeting # Slide : 3


Linux Based Networks Zahid Shafique, Instructor

who options
Options Description
-H Display headings above each column
-u List only users who are currently logged in
-i Users idle time
-q All login names and total no of users logged on
-w, -T message status + is for y and – is for n

#who –uH
NAME LINE TIME IDLE PID COMMENT
root console Dec 13 08:00 . 10340
user1 tty02 Dec 13 10:37 . 11929 Tech-89.2
user2 tty03 Dec 13 11:02 0:04 4761 Sales-23.4
user35 tty05 Dec 13 09:21 1:07 10426
zahid ttys7 Dec 11 18:49 old 10770
Topic Heading Class Meeting # Slide : 4
Linux Based Networks Zahid Shafique, Instructor

Field Description
Field Description
NAME Lists the user's login name.
LINE Lists the line or terminal being used.
TIME Lists the time the user logged in.
IDLE Lists the hours and minutes since the last activity
on that line. A period is displayed if activity
occurred within the last minute of system time. If
more than 24 hours has elapsed since the line was
used, the word old is displayed.
COMMENTS Lists the contents of the comment field if
comments have been included in /etc/inittab or if
there are network connections.

Topic Heading Class Meeting # Slide : 5


Linux Based Networks Zahid Shafique, Instructor

Using w to List Users Logged in to the System


&
What they are doing

Issue the command

#w

Topic Heading Class Meeting # Slide : 6


Linux Based Networks Zahid Shafique, Instructor

Reporting On the Status of Processes with ps

The ps (process status) command reports on the status of processes.


You can use it to determine
Which processes are running,
Whether a process has completed,
Whether a process is hung (having some difficulty),
How long a process has run,
The resources a process is using,
The relative priority of a process,
The PID needed before you can kill a process.

All this information is useful to a user and very useful to a system


administrator.

Topic Heading Class Meeting # Slide : 7


Linux Based Networks Zahid Shafique, Instructor

Monitoring Processes with ps

A common use of the ps command is to monitor background jobs and


other processes on the system.

Because background processes don't communicate with your screen and


keyboard in most cases, you use ps to track their progress.

Topic Heading Class Meeting # Slide : 8


Linux Based Networks Zahid Shafique, Instructor

ps commands Headings
The ps listing displays four default headings as indicators of the
information in the fields below each heading: PID, TTY, TIME, and
COMMAND.
Headings in the Output of ps

Field Explanation
PID The process identification number
TTY The terminal on which the process originated
TIME The cumulative execution time for the process, in minutes
and seconds
COMMAND The name of the command being executed

Topic Heading Class Meeting # Slide : 9


Linux Based Networks Zahid Shafique, Instructor

Common output fields for ps command


Field Explanation

USER or UID Process owner's username.


PID Process ID.
%CPU CPU utilization of the process.
%MEM Percentage of memory (in kilobytes)
utilization of the process.
SIZE Size (in kilobytes) of virtual memory used
by the process.
RSS Resident set size or size of real memory (in
kilobytes) used by the process.
TTY Terminal (tty) associated with the process.
Usually the tty name is shortened.
For example p7 is displayed for /dev/ttyp7.
Topic Heading Class Meeting # Slide : 10
Linux Based Networks Zahid Shafique, Instructor

output fields (cont…)

Topic Heading Class Meeting # Slide : 11


Linux Based Networks Zahid Shafique, Instructor

Process Status
• The process status can be shown under the STAT
column issued by ps or top.
Code Description
R Runable
D In disk (or
(or short-term)
short-term) wait
wait
I, S Sleeping (>20 sec, < 20 sec)
T Stopped
Z Zombie
Zombie
> Process has higher than normal priority
N Process has lower than normal priority
< Process is exceeding soft limit on memory use
X Process is being traced or debugged
L Some pages are locked in core
W Process is swapped out
+ Process is in the foreground of its control terminal
Topic Heading Class Meeting # Slide : 12
Linux Based Networks Zahid Shafique, Instructor

output fields (cont…)


START Process start time and date.
TIME Total CPU time used by the process.
COMMAND Command line being executed.
NI The nice priority number.
PRI Process priority number.
PPID Process ID of the parent process.
WCHAN Name of the kernel function where a
process is sleeping. The name of the
function is retrieved from the
/boot/system.map file
FLAGS A numeric flag associated with the process.
Topic Heading Class Meeting # Slide : 13
Linux Based Networks Zahid Shafique, Instructor

Commonly used ps options

Flag Description
a Shows processes of other users also.
f Shows processes and sub processes.
h Specifies no header.
l Indicates the long format.
r Specifies running processes only.
txx Processes associated with tty terminal.
u Indicates the user format; gives username and start
time.
x Shows processes without controlling terminal.

Topic Heading Class Meeting # Slide : 14


Linux Based Networks Zahid Shafique, Instructor

To obtain a full listing, use this command:

$ ps -uax

$ps -u

Topic Heading Class Meeting # Slide : 15


Linux Based Networks Zahid Shafique, Instructor

To list processes for two terminals


To list processes for two terminals (for example, tty1 and tty2), use the
following command:

$ ps -t ``1 2''
PID TTY TIME COMMAND
32 tty01 0:05 bash
36 tty02 0:09 bash
235 tty02 0:16 vi calendar

Topic Heading Class Meeting # Slide : 16


Linux Based Networks Zahid Shafique, Instructor

Processes owned by a particular user

#ps au | grep username

Where username is the name of the user

Topic Heading Class Meeting # Slide : 17


Linux Based Networks Zahid Shafique, Instructor

Terminating Processes with kill

Sometimes you want or need to terminate a process. The following are


some reasons for stopping a process:

It's using too much CPU time.


It's running too long without producing the expected output.
It's producing too much output to the screen or to a disk file.
It appears to have locked a terminal or some other session.
It's using the wrong files for input or output because of an operator or
programming error.
It's no longer useful.

Topic Heading Class Meeting # Slide : 18


Linux Based Networks Zahid Shafique, Instructor

Using kill to Send Signals to Processes

The kill command sends signals to the program to demand that a process
be terminated or killed. To use kill, use either of the following forms:
kill PID(s)
kill -signal PID(s)

Number Signal Description


1 SIGHUP Reread configuration files
9 SIGKILL Terminate the process immediately
15 SIGTERM Terminate in a normal manner

Topic Heading Class Meeting # Slide : 19


Linux Based Networks Zahid Shafique, Instructor

killall

#killall process name

Topic Heading Class Meeting # Slide : 20


Linux Based Networks Zahid Shafique, Instructor

Scheduled Processes - cron


• The cron command handles the periodic execution:
– Daily - remove unused or unneeded core files, get rid of files no
longer in use in the /tmp directory, monitor the disk space on user
home directories, network distribution of configuration files.
– Weekly - performing checks on the filesystem, check for long
running processes, clear files that receive log information.
– Monthly - run monthly reports, locate files that are not being used.
• cron scans the instructions in the crontab file periodically
and execute all commands in it. (/etc/crontab or /usr/lib/crontab)
• In SunOS, crontab directory is used instead of single file.
– users use crontab command to submit their own instruction files into
the contab directory.
– two files control the accessibility of the crontab command:
cron.allow and cron.deny.
• Some versions of UNIX will keep a log file (/var/cron/log).
Topic Heading Class Meeting # Slide : 21
Linux Based Networks Zahid Shafique, Instructor

Format of Crontab files


minute hour day month weekday username command
Field
Field Description
Description Range
Range
minute
minute minuteof
minute ofthe
thehour
hour 00to
to59
59
hour
hour hourof
hour ofthe
theday
day 00to
to23
23
day
day dayof
day ofthe
themonth
month 11to
to31
31
month
month Monthof
Month ofthe
theyear
year 11to
to12
12 jan
jantotodec
dec
weekday
weekday Dayof
Day ofthe
theweek
week 11to
to7/0
7/0 mon
monto tosun
sun

Examples:
0 0 * * 1 (cd /home/dccyril/project; make)
make the project only on Mondays mid-night.
20 1 * * * find /tmp –atime +3 –exec rm –f {}';'
remove all tmp files that have not been accessed in 72 hrs at 1:20am
everyday.
22 23 * * 1-4,7 /staff/dccyril/bin/acct-script
runs the acct-script at 11:55pm on Mon, Tue, Wed, Thu and Sun.

Topic Heading Class Meeting # Slide : 22


Linux Based Networks Zahid Shafique, Instructor

Scheduled Processes - at
• at: schedule the process.
– allows user to execute commands at a specified time.
at timeformat command
– Eg. at 6pm nightlyprocess
at 1am tomorrow command1
at 4pm +3 days command2
at 10am Jul 31 command3
at now next fri command4
at 14:45 Sep 14 00 command5
– Use atq command to list all the pending jobs
– Use atrm command to remove the jobs.
– The permission for using at is determined by the files
/etc/at.allow and /etc/at.deny.
• In Linux, you can add a set of commands after
issuing the at command.
Topic Heading Class Meeting # Slide : 23
Linux Based Networks Zahid Shafique, Instructor

Topic Heading Class Meeting # Slide : 24


Linux Based Networks Zahid Shafique, Instructor

Exercise:

Topic Heading Class Meeting # Slide : 25


Linux Based Networks Zahid Shafique, Instructor

Homework
• Homework this week:

• Next week:

Topic Heading Class Meeting # Slide : 26