Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Mar 2004 18:40:14 +0100
From:      "Cyrille Lefevre" <cyrille.lefevre@laposte.net>
To:        "David Schultz" <das@freebsd.org>, "Garance A Drosihn" <drosih@rpi.edu>
Cc:        arch@freebsd.org
Subject:   posix ps (was Re: Adding `pgrep' and `pkill' to /usr/bin)
Message-ID:  <1a9c01c41359$b3da45e0$7890a8c0@dyndns.org>
References:  <p0602046abc879c5fe2f9@[128.113.24.47]> <20040325070120.GA67497@VARK.homeunix.com>

next in thread | previous in thread | raw e-mail | index | archive | help
"David Schultz" <das@freebsd.org> wrote:

> On Wed, Mar 24, 2004, Garance A Drosihn wrote:
> > I noticed the upcoming version of OpenBSD will add the commands
> > `pkill' and `pgrep', which they picked up from NetBSD.  These
> > commands also exist in Solaris and Linux.  Anyone mind if I add
> > them to FreeBSD?  I'd just pick up the versions from NetBSD, and
> > make whatever changes are needed for them to work on FreeBSD.
> >
> > (I actually had an idea of adding another option or two to `ps'
> > which would have given it abilities similar to `pgrep', but once
> > I noticed these I figured it would make more sense to add them)
>
> I think it would be *great* to import any and all of the Solaris
> proc tools into FreeBSD.  I tend to think of these utilities as
> ps(1), fstat(1), and friends done the proper Unix way (with lots
> of simple tools that can be combined for powerful effect.)
> For those who haven't seen the rest of the tools, take a look at:


Hi,

two years ago, I've added posix syntax and so to my locally ps(1). for instance,
I'm
currently adding the notion of dynamic personalities (the term comes from linux)
instead of static #define such as... say :

$ ps -X help
any bsd bsd43reno bsd44 default extended freebsd hpux irix netbsd none openbsd
pedantic posix relaxed solaris sunos susv3 tru64

personalities enable options such as :
bsd ps :
    -g and -n from sunos, -s from tru64 and some other options.
posix ps : see susv3 man (see
http://www.opengroup.org/onlinepubs/007904975/toc.htm)
    -j from all except posix
    -c, -y and -P from solaris
    -C cmdlist (ala pgrep :) and -x from hpux
    -M from irix
    and some others
they also enable many keywords such as :
    RUSAGE and co from tru64, class and psr from solaris, and many others
(mostly aliases)

when finished, I'll probably submit these changes as a port in the meantime
since I suppose -arch will reject these important changes to a native command.
the most important and not done part is... the manual page. any volonteers ?

here are some sample outputs :

$ PERSONALITY=freebsd ps -?
usage: ps [-aCcefHhjlmrSTuvWwxZ] [-M core] [-N system] [-O fmtlist]
          [-o fmtlist] [-p pid] [-t tty] [-U user] [-X perslist]
       ps -L
       ps -X help
$ PERSONALITY=freebsd,+extended ps -?
usage: ps [-aCcefgHhjlmnrSsTuvWwxZ] [-M core] [-N system] [-O fmtlist]
          [-o fmtlist] [-p pidlist] [-t ttylist] [-U user] [-X perslist]
       ps -L
       ps -X help
$ PERSONALITY=susv3 ps -?
usage: ps [-Aadefl] [-G grouplist] [-g pgrplist] [-n system [-n core]]
          [-o fmtlist] [-p pidlist] [-t ttylist] [-U ruserlist] [-u userlist]
          [-X perslist]
       ps -o help
       ps -X help
$ PERSONALITY=susv3,+extended ps -?
usage: ps [-AacdefjlPxy] [-C cmdlist] [-G grouplist] [-g pgrplist]
          [-n system [-n core]] [-O fmtlist] [-o fmtlist] [-p pidlist]
          [-s sidlist] [-t ttylist] [-U ruserlist] [-u userlist] [-X perslist]
       ps -o help
       ps -X help
$ PERSONALITY=hpux ps -?
usage: ps [-AacdefHjlPxz] [-C cmdlist] [-G grouplist] [-g pgrplist]
          [-n system [-n core]] [-o fmtlist] [-p pidlist] [-R prmgrplist]
          [-s sidlist] [-t ttylist] [-U ruserlist] [-u userlist] [-X perslist]
          [-Z psetlist]
       ps -o help
       ps -X help
$ PERSONALITY=hpux,+extended ps -?
usage: ps [-AacdefHjlPxyz] [-C cmdlist] [-G grouplist] [-g pgrplist]
          [-n system [-n core]] [-O fmtlist] [-o fmtlist] [-p pidlist]
          [-R prmgrplist] [-s sidlist] [-t ttylist] [-U ruserlist]
          [-u userlist] [-X perslist] [-Z psetlist]
       ps -o help
       ps -X help
$ PERSONALITY=solaris ps -?
usage: ps [-AacdefjLlPy] [-G grouplist] [-g pgrplist] [-n system [-n core]]
          [-o fmtlist] [-p pidlist] [-s sidlist] [-t ttylist] [-U ruserlist]
          [-u userlist] [-X perslist]
       ps -o help
       ps -X help
$ PERSONALITY=solaris,+extended ps -?
usage: ps [-AacdefjLlPxy] [-C cmdlist] [-G grouplist] [-g pgrplist]
          [-n system [-n core]] [-O fmtlist] [-o fmtlist] [-p pidlist]
          [-s sidlist] [-t ttylist] [-U ruserlist] [-u userlist] [-X perslist]
       ps -o help
       ps -X help
$ PERSONALITY=tru64 ps -?
usage: ps [-Aadefjlmr] [-G grouplist] [-g pgrplist] [-n system [-n core]]
          [-O fmtlist] [-o fmtlist] [-p pidlist] [-s sidlist] [-t ttylist]
          [-U ruserlist] [-u userlist] [-X perslist]
       ps -o help
       ps -X help
$ PERSONALITY=tru64,-posix ps -?
usage: ps [-AaeghjlmrSsTuvwx] [-M core] [-N system] [-O fmtlist] [-o fmtlist]
          [-t tty] [-X perslist]
       ps -L
       ps -X help
$ PERSONALITY=tru64,bsd ps -?
same as above
$¨PERSONALITY=susv3,any ps -o help
%cpu %mem acflag args class command cpu cursig etime f gid group inblk intpri
jobc ktrace label lim lockname login lstart majflt minflt msgrcv msgsnd mwchan
nice nivcsw nsigs nswap nvcsw nwchan opri oublk paddr pagein pgid pid ppid pri
pset psr re rgid rgroup rss rtprio ruid ruser scnt sid sig sigcatch sigignore
sigmask sl start state stime svgid svuid systime sz tdev time tpgid tsid tsiz
tt tty ucomm uid upr user usertime vsz xstat
DFMT F5FMT FL5FMT JFMT L5FMT LFMT RUSAGE SCHED SFMT THREAD UFMT VFMT acflg
addr blocked c caught cls cmd comm cp cputime dev flag flags ignored inblock l
logname longtname longtty maxrss ni nsignals oublock pcpu pending pmem policy
psxpri rssize rsz runame s scount sess session size slp stat tname traceflag
tsess tsession u_procp uname uprocp usrpri util vsize wchan wname

$ ps -O RUSAGE
  PID  MINFLT  MAJFLT NSWAP INBLK OUBLK  MSGSND  MSGRCV NSIGS NVCSW NIVCSW    S
TTY           TIME COMMAND
76543     166       0     0     0     0       0       0     0     0      5 OL+
ttyp1     00:00:00 ps
$ PERSONALITY=tru64,bsd ps -s
  UID   PID  PENDING  BLOCKED  IGNORED   CAUGHT STAT  TT      TIME COMMAND
    0 16231        0        0 18488000        0 OL+ p1    0:00.04 ps -s
$ PERSONALITY=susv3 ps -fl
      F    S UID    PID  PPID   C PRI  NI     ADDR    SZ WCHAN      STIME TTY
TIME CMD
   4002 OL+ root 50522 16850  11  97   0 c20dc6e0   284 -       09:22:06 ttyp1
00:00:00 ps -fl
$ PERSONALITY=solaris ps -flcy
   S UID    PID  PPID CLS    PRI   RSS    SZ WCHAN      STIME TTY           TIME
CMD
OL+ root 54243 16850 normal 180   972   284 -       09:23:05 ttyp1     00:00:00
ps -flcy
# PERSONALITY=susv3,+extended ps -lcy -C seti
   S   UID   PID  PPID CLS    PRI   RSS    SZ WCHAN  TTY           TIME CMD
RN+   1012 28746 13529 normal 223 14504 16284 -      consolectl 12-08:27:48
setiathome
$ PERSONALITY=tru64,+extended ps -ly
   S   UID   PID  PPID %CPU PRI  NI   RSS   VSZ WCHAN  TTY           TIME CMD
OL+/     0 59242 16850  0.0 103   0  992K 1.51M -      ttyp1     00:00:00 ps5

PS : note the S (O means on cpu), RSS.VSZ (tru64 format) and TIME (posix format)
columns...

all internals are dynamically generated, such as format strings :

for native freebsd :
label:Z user:!nju uid:!d!vnl pid:djl1uv ppid:jl pgid:j jobc:j cpu:l pri:l nice:l
%cpu:u %mem:u vsz:lu rss:lu mwchan:!nl tt:d2u state:djl2uv start:u tt:jl
time:djl2uv sl:v re:v pagein:v vsz:v rss:v lim:v tsiz:v %cpu:v %mem:v
command:djl2uv

for native susv3 :
f:!ylx s:lx user:fx uid:l pid:dflx ppid:flx c:!cflx pri:!clx intpri:c nice:!clx
addr:!ylx vsz:lx wchan:lx tty:dl stime:fx tty:fx time:!Ldflx comm:dl args:fx


for extended susv3 :
label:M f:!ylx s:lx user:fx uid:l pid:dflxj1 ppid:flxj pgid:j sid:j psr:P
c:!cflx class:c pri:!clx intpri:c nice:!clx psr:P addr:!ylx rss:y vsz:lx=SZ
wchan:lx tty:dlj s:2 stime:fx tty:fx2 time:!Ldflxj2 comm:dlj2 args:fx

PS : 1 and 2 stand for -O, x stands for -fl, !x say not -x

Cyrille Lefevre.
-- 
home: mailto:cyrille.lefevre@laposte.net



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1a9c01c41359$b3da45e0$7890a8c0>