courses:cs334-201503:lectures:unixps.pptx (41.2 KB)

Download Report

Transcript courses:cs334-201503:lectures:unixps.pptx (41.2 KB)

Chapter 3: Linux &
Processes
Let’s look at some data
The Process Status (ps) command
• On every UNIX-like operating system, the process status command
(ps) displays information about active processes. Every operating
system's version of ps is slightly different, and the documentation
describes several kinds of options:
• And it gets exhausting after a while!
• Really! Check the man pages.
The ps command “cheat sheat”
• I recommend using only two options:
-e
Select all processes. Identical to -A.
-f
o full-format listing. This option can be combined with
many other UNIX-style options to add additional
columns. It also causes the command arguments to be
printed. When used with -L, the NLWP (number of
threads) and LWP (thread ID) columns will be added.
See the c option, the format keyword args, and the
format keyword comm.
The ps command “cheat sheat”
• Use ps –ef to get all of the process data available
• Then just look for the information you want. But don’t scan the output
yourself…
• Use the pipe ( | ) command character to feed the output of the ps
command to a search command
• …and let the search command do it for you.
• The search command? grep
The grep command
• grep, naturally, means search: (globally search a regular expression
and print)
grep [OPTIONS] PATTERN [FILE...]
1. No need to get into details on regular expressions.
2. However, there are a few options worth remembering
grep -i “data" some_file (case insensitive search)
grep -r “data" * (recursive search)
grep -v “data" some_file (obverse search, i.e. everything without “data”
ps and pipe and grep
• If you’re not on a personal computer (i.e. a timeshare machine)
• Then there will be multiple users
• Combine all three commands to look for processes for particular
users!
• ps –ef | grep userid
a) Get all processes with a nice format,
b) Pipe the results to another command (grep)
c) And search for userid amongst the results.