Commit graph

72 commits

Author SHA1 Message Date
Garance A Drosehn 5dfd7724a3 If <x> is a process id that does not exist, then just print the header
(if any) and exit, thus matching the behavior on -stable and other OS's.
My earlier attempt to fix this (v1.65) only seemed to work because of a
lucky random value in nentries (which was not being initialized back
when I tested that earlier patch).
2004-03-28 03:00:56 +00:00
Garance A Drosehn e3c4e1dd77 If a non-existent user is given as part of `-U userlist', treat it as
a fatal error instead of a minor warning.  It is possible that a few
users are used to the previous behavior, but I'm claiming it was a bug.
2004-03-27 22:14:42 +00:00
Garance A Drosehn 29d58b106b Explicitly wrap two long-ish linesi of code, to make them easier to read. 2004-03-27 21:59:54 +00:00
Garance A Drosehn b34f38ae9e Change the #if-ish logic which is used to add the -f' option when ps'
is compiled with LAZY_PS, so that there is only one PS_ARGS string to
modify when changing the option-list.  Also get `-f' to show up in the
usage() statement when compiled with LAZY_PS.
2004-03-27 21:56:49 +00:00
Garance A Drosehn 4a355d176d Move the 'f' case so it shows up in the right place, alphabetically. 2004-03-27 21:40:04 +00:00
Garance A Drosehn a4c8a745a8 Support more POSIX/SUSv3 options:
- Change `-p' to allow a list of process IDs, and `-t' to allow a list
  of terminal names, instead of only a single value for each.
- Add the `-A' option of SUSv3, which is exactly the same as `-ax'.
- Add the `-G gidlist' (group id).
- Allow any of these "selector options" to be specified multiple times,
  and have `ps' keep adding to a given list -- instead of replacing the
  previously-specified values.
- Fix interactions between selector-options, so that: "If any are
  specified, ... ps shall select the processes represented by the
  inclusive OR of all the selection-criteria options." (from SUSv3)
- Add a `-X' option, which is the reverse of the `-x' option.

- various minor improvements in parsing and error handling.

This does not get us to match POSIX/SUSv3, but it gets us closer.  The
`-g pgidlist', `-R ruserlist' and `-s sidlist' options mentioned in
freebsd-standards are still under debate, so they skipped for now.
It should be true that this introduces no user-visible incompatible
changes, except to support "new stuff" that was not supported before.
2004-03-27 18:22:17 +00:00
Garance A Drosehn 2e6c6ac4d7 Fix 'ps -p proclist' and 'ps -u userlist' so the command returns non-zero
if no processes were matched.  Also sorts the list of 'int's in main, as
long as I had to add another one...

Noticed by:	Nate Lawson
MFC after:	10 days
2004-03-18 01:28:23 +00:00
Garance A Drosehn 4e8b6a6fb0 Improvements to 'ps -p <x>'. If <x> is a process id that does not exist, then
just print the header (if any) and exit, thus matching the behavior on -stable
and other OS's.

Also adds support for <x> being a comma-separated list of processes, and does
a much better checking for invalid-values of <x>, such as 'ps -p someword'.

Reviewed by:	mentioned on freebsd-current
MFC after:	10 days
2004-03-17 22:46:58 +00:00
Daniel Eischen d75c1d8381 Allow the -H option to show threads when selecting by uid, tty,
and pid.
2004-02-22 17:59:31 +00:00
Scott Long 48b8c0de5a Add the -H option to ps(1) to display all kernel visible threads in each
process.  The default behavior of showing only the process is retained as
the default.
2003-06-12 16:53:55 +00:00
Philippe Charnier eaed5652bf Display elapsed time (-o etime) using [[dd-]hh:]mm:ss, which according to
Solaris man page is the POSIX way.

Reviewed by:	jmallett
2003-02-05 13:18:17 +00:00
Juli Mallett 78b1878a16 Per-variable\ entry headers, to allow the 'ps -otime -otime=FOO' or similar
case to do the right thing and affect exactly one column.  This is consistent
with GNU ps(1) in BSD mode, and POLA.
2003-01-19 00:31:16 +00:00
Juli Mallett fde411d5a1 When inserting a non-user-specified (e.g. not via -o or -O) format, don't dupe
one that is already there.  This is consistent with GNU ps(1)'s BSD mode, and
POLA.

Reported by:	Andy Farkas <andyf@speednet.com.au>
Tested by:	Andy Farkas <andyf@speednet.com.au>
2003-01-19 00:22:34 +00:00
Robert Watson 2af538eb48 Use the MAC interface to list process MAC labels rather than using
the LOMAC-specific interface (which is being deprecated).  The
revised LOMAC using the MAC framework will export levels listable
using this mechanism.

Approved by:	re
Obtained from:	TrustedBSD Project
Sponsored by:	DARPA, Network Associates Laboratories
2002-10-24 00:00:57 +00:00
Juli Mallett daed3ad661 Prevent ps(1) from doing idiotic munging of things in a -ofmt= string.
God I hate the backwards compatability crap here.
2002-09-03 05:44:00 +00:00
Robert Drehmel a755f1c9d0 - Use (MAXLOGNAME - 1) where UT_NAMESIZE was used to be able to
(-)remove the inclusions of <utmp.h>.
2002-07-08 09:08:51 +00:00
David E. O'Brien 2749b14129 Consistently use FBSDID 2002-06-30 05:15:05 +00:00
Maxim Sobolev 41623b2d75 Don't try to decode old-style options if the argv[1] begins with `-' and the
second character represents some option taking an argument. This fixes
problem when ps(1) is invoked for examply as follows:

$ ps -Ufoobar1234

the above example results in option string being interpreted as
-U foobarp1234 - note extra `p'.

Reported by:	Vladimir Sotnikov <vovan@kyivstar.net>
MFC after:	2 weeks
2002-06-20 14:55:53 +00:00
Juli Mallett ba2cd77062 Use a global `now' variable for the current time, and initialise it at
startup, right after calling setlocale(3).
2002-06-06 21:21:25 +00:00
Juli Mallett 4fa7d7880d Widen the scope of fmt.c::1.19 and consistently use errx(3) if malloc(3) [or
realloc(3)] happens to fail, everywhere in ps(1).

Discussed with:	bde, charnier (a while ago)

fmt_argv() can no longer return NULL, so don't bother checking.

Submitted by:	bde
2002-06-05 18:11:25 +00:00
Juli Mallett c0716492d4 Comma seperate format lists, since space is no longer up to the task.
Poked by:	David Wolfskill <david@catwhisker.org>
Pointy hat to:	jmallett
2002-06-05 17:31:44 +00:00
Tim J. Robbins 4f18100d73 Respect setting of the COLUMNS environment variable (SUSv3) 2002-06-04 10:20:10 +00:00
Chris D. Faulhaber a5b0f3020c errx()/strerror() -> err() 2002-04-07 04:59:13 +00:00
Matthew Dillon d9a5f8900a Revert wchan functionality. Add 'mwchan' to supply new duel mutex/msleep
functionality and make it the default.

With additional improvements by: Mark Peek <mp@FreeBSD.org>
2002-02-21 18:27:16 +00:00
Mark Murray 871e8d8c59 WARNS=4 fixes (incomplete, so set NO_WERROR), and lots of extra
cleanup courtesy of automatic checking (lint).
2002-02-03 14:43:04 +00:00
Warner Losh 46251dde8f o __P has been reoved
o Old-style K&R declarations have been converted to new C89 style
o register has been removed
o prototype for main() has been removed (gcc3 makes it an error)
o int main(int argc, char *argv[]) is the preferred main definition.
o Attempt to not break style(9) conformance for declarations more than
  they already are.
2002-02-02 06:48:10 +00:00
Ruslan Ermilov 9e1c120c8e Remove a stray :' after v' in the getopt() call.
Submitted by:	bde
2002-01-28 13:43:22 +00:00
Ruslan Ermilov 831c910a30 GC the -W option. kvm(3) doesn't read swap for almost 10 years.
PR:		docs/34134
Reviewed by:	bde, peter
MFC after:	1 month
2002-01-28 09:43:26 +00:00
Maxim Sobolev f1ff35aecb Add missed includes.
Reviewed by:	md5
2002-01-15 12:23:52 +00:00
Brian Feldman 7304f61f9e Add LOMAC options (the "Z" flag in both cases) to display extra information
in ls(1) and ps(1).

Sponsored by:	DARPA, NAI Labs
2001-11-26 22:21:15 +00:00
Peter Wemm fbb75ab833 Handle kvm_getprocs() returning nothing. Dont pass -1 to a size
for malloc().
2001-08-24 09:53:26 +00:00
Brian Somers 380434d488 Only capitalise the last `t' in ps's first argument when it's
actually part of an option argument.

Submitted by:	Chris Costello <chris@calldei.com>
MFC after:	6 weeks
2001-08-16 02:41:42 +00:00
Warner Losh 5782e27253 Use PATH_MAX rather than MAXPATHLEN. 2001-05-30 03:27:07 +00:00
Mark Murray 25bba4f6ad Depollute headers now that the VM headers DTRT. 2001-05-03 11:49:44 +00:00
Mark Murray 325a83b456 Compensate for header dethreading. 2001-05-01 08:39:23 +00:00
Brian Somers 52f8369e69 The sess column went away last December with v1.26 of keyword.c
Remove it from ``jfmt''.

Forgotten by: mckusick
2001-04-07 02:53:35 +00:00
Andrey A. Chernov f59105eedb Small optimization: set use_ampm only when needed 2001-03-03 01:46:58 +00:00
Andrey A. Chernov 080175194f Use AM/PM time only when available in locale 2001-03-02 23:53:36 +00:00
John Baldwin e0aa5ab718 - Catch up to new proc flags. 2001-01-24 12:59:50 +00:00
Kirk McKusick 1f7d250182 Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
Brian Somers cf22dcfc33 Support multiple (comma separated) names as arguments to -U
PR: 11051
2000-09-26 01:03:16 +00:00
Will Andrews f8c9c11c5c Fix the exit code for the case where nentries == 0; if a PID doesn't exist,
ps(1) should not be returning a success code (0), it should return an
error code (1).  This was fixed on OpenBSD over 3 years ago.

PR:		19069
Submitted by:	Jim Sloan <odinn@atlantabiker.net>
Reviewed by:	rwatson
2000-07-08 05:13:10 +00:00
Peter Wemm 602a69d61e Use eproc.e_stats, not a series of crude hacks to fetch it from the u-area.
Also, fix some indentation that got messed up somehow..
1999-11-17 12:52:42 +00:00
Poul-Henning Kamp b9df5231ca Introduce commandline caching in the kernel.
This fixes some nasty procfs problems for SMP, makes ps(1) run much faster,
and makes ps(1) even less dependent on /proc which will aid chroot and
jails alike.

To disable this facility and revert to previous behaviour:
        sysctl -w kern.ps_arg_cache_limit=0

For full details see the current@FreeBSD.org mail-archives.
1999-11-16 20:31:58 +00:00
Kris Kennaway bdfebd8480 Typo (appropiate -> appropriate)
Obtained from:	OpenBSD (inspired by)
1999-11-15 03:37:57 +00:00
Peter Wemm 2a4562393f $Id$ -> $FreeBSD$ 1999-08-27 23:15:48 +00:00
Bill Paul bb22740673 On FreeBSD/alpha, ps(1) does not correctly report process start times
and CPU runtime because it can't access the user area via /proc/<pid>/mem.
This is because the uarea is not mapped into the process address space
at USRSTACK on the alpha like it is on the x86.

Since I'm haven't been able to wrap my brain around the VM system enough
to be able to figure out how to achieve this mapping, and since it's
questionable that such an architectural change is correct, I implemented
a workaround to allow ps(1) to read the uarea from /dev/kmem using
kvm_read() instead of from the process address space via kvm_uread().
The kludge is hidden inside #ifdef __alpha__/#endif so as not to impact
the x86. (Note that top(1) probably uses this same gimmick since it works
on FreeBSD/alpha.)

Reviewed by: dfr
1999-04-01 14:45:18 +00:00
Poul-Henning Kamp 85082fc3c3 Pick up kernel variables/constants using sysctl rather than through /dev/mem
Use /dev/null for opening the kvm library, we don't need access to /dev/mem
anymore.

ps can now run without the setgid(kmem) bit.  If it does it will not be
able to show argv/envp for another uid's processes unless you are root.
1998-06-30 21:34:14 +00:00
Philippe Charnier c9a8d1f4dd Correct use of .Nm. Add rcsid. 1998-05-15 06:30:58 +00:00
Dima Ruban 6425bb4314 cosmetic change for optstring 1998-02-18 22:45:22 +00:00