pavement

Ps

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
m (Reverted edits by 83.211.3.16 (Talk); changed back to last version by Jimbo)
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
[[ps]] will show your running processes. If run from a regular user shell or an xterm window, it'll only show you '''your''' processes. If run as root, it will show ''all'' processes.
 
[[ps]] will show your running processes. If run from a regular user shell or an xterm window, it'll only show you '''your''' processes. If run as root, it will show ''all'' processes.
  
There were different switches used in different versions of [[ps]] -- historically, [[SysV]] needs the '''-ef''' switches to show all processes and [[BSD]] needed '''-aux'''. [[ps]] is now smarter and will accept either switch and show you what you wanted to see.  It is, however, a good idea to feed [[ps]] the switches with no hyphen in front of them - ie '''ps aux''' - because while FreeBSD understands either syntax, Linux only understands the latter.
+
[[BSD]] does not support the switches (options) defined by the [[UNIX]] standard because historical BSD implementations assigned conflicting meanings to these switches. Enhancements commonly found on [[Linux]] and [[Solaris]] are likewise unavailable. Near-equivalent common options are as follows:
  
 +
{| border="1" cellpadding="5" cellspacing="0"
 +
! UNIX !! BSD
 +
|-
 +
| ps || <nowiki>ps opid,tty,time,comm | egrep ' '`ps otty= $$`' |TT'</nowiki>
 +
|-
 +
| ps -ef || ps aux
 +
|-
 +
| ps -el || ps axl
 +
|-
 +
| ps -u x || <nowiki>ps axo ruser,pid,tty,time,comm | awk '/^x |TT/{printf("%5s %-8s %11s %s\n", $2,$3,$4,$5)}'</nowiki>
 +
|-
 +
| ps -e -C bash || <nowiki>ps axo pid,tty,time,comm | egrep 'PID.*TT| b[a]sh$'</nowiki>
 +
|}
 +
 +
While the [[BSD]] ps does ignore the "-" in front of options, it is better to avoid using it. Besides being less to type, this makes your habits and scripts compatible with several other systems. [[Linux]], [[AIX]], and [[Tru64]] all follow the UNIX standard when the "-" is used. They act like BSD when the "-" is not used.
 +
 +
For a BSD-style ps on a [[Solaris]] system, use /usr/ucb/ps instead of the normal UNIX-standard ps.
 +
 +
==Common flags==
 +
 +
;a: all users, not just the user running the [[ps]] command
 +
;u: show system info on commands (user, pid, cpu% etc)
 +
;c: show the command only, not the path to it
 +
;x: show processes that don't have a terminal controlling them
 +
;r: sort by CPU use
 +
;w: wide output
 +
 
[[Category:System Commands]]
 
[[Category:System Commands]]

Latest revision as of 13:09, 5 May 2007

ps will show your running processes. If run from a regular user shell or an xterm window, it'll only show you your processes. If run as root, it will show all processes.

BSD does not support the switches (options) defined by the UNIX standard because historical BSD implementations assigned conflicting meanings to these switches. Enhancements commonly found on Linux and Solaris are likewise unavailable. Near-equivalent common options are as follows:

UNIX BSD
ps ps opid,tty,time,comm | egrep ' '`ps otty= $$`' |TT'
ps -ef ps aux
ps -el ps axl
ps -u x ps axo ruser,pid,tty,time,comm | awk '/^x |TT/{printf("%5s %-8s %11s %s\n", $2,$3,$4,$5)}'
ps -e -C bash ps axo pid,tty,time,comm | egrep 'PID.*TT| b[a]sh$'

While the BSD ps does ignore the "-" in front of options, it is better to avoid using it. Besides being less to type, this makes your habits and scripts compatible with several other systems. Linux, AIX, and Tru64 all follow the UNIX standard when the "-" is used. They act like BSD when the "-" is not used.

For a BSD-style ps on a Solaris system, use /usr/ucb/ps instead of the normal UNIX-standard ps.

[edit] Common flags

a
all users, not just the user running the ps command
u
show system info on commands (user, pid, cpu% etc)
c
show the command only, not the path to it
x
show processes that don't have a terminal controlling them
r
sort by CPU use
w
wide output
Personal tools