Commit Graph

304 Commits

Author SHA1 Message Date
gad
ec3d9baab5 Replace pscomp() with a cleaner version, mostly written by bde (*).
This corrects a problem of lost-precision for `-r' (sort-by-CPU).  Also,
for sort-by-CPU and sort-by-memory, any processes which have the same
value CPU or MEMORY are now sorted by TTY and then (if needed) by pid.

(* - I just added the NODEV checks, after doing some testing of my own)

Submitted by:	bde
MFC after:	1 week
2004-03-30 01:45:23 +00:00
gad
e706cf764f Oops. Remove some ';'s in #defines added by a previous update.
Noticed by:	bde
2004-03-29 03:03:28 +00:00
gad
14c427e33e Have this source explicitly include <sys/proc.h>, since it references
values such as P_CONTROLT and PS_INMEM.  But this still won't define
PID_MAX for us, since that is hidden inside of '#ifdef _KERNEL'.

Noticed by:	bde
2004-03-29 01:27:13 +00:00
gad
f23f565e5e Since "kp" is a pointer, I should be comparing against NULL not 0.
Noticed by:	bde
2004-03-29 01:18:13 +00:00
gad
36a78467c4 Various style improvements, mostly in comments and indentation.
Suggested by:	bde (well, for most of them)
2004-03-29 01:15:27 +00:00
gad
6e6851b604 In the routines I've been working on, sort the variable declartions
so that non-pointers are listed after pointer-type variables.

Noticed by:	bde
2004-03-29 00:25:09 +00:00
gad
1455cfb154 Split two 'fmt' strings so they're easier to read on 80-char windows. 2004-03-29 00:16:19 +00:00
gad
f18215deb8 Sort the declarations of global variables. 2004-03-29 00:12:03 +00:00
gad
3dddad185c Sort the routine prototypes. 2004-03-28 23:44:29 +00:00
gad
72d6e1aaae 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
gad
c148ed96ea Fix `-o rtprio' so it prints the correct value.
PR:		bin/59417
Submitted by:	Jan Willem Knopper
This fix by:	bde (in the audit-trail of the PR)
2004-03-28 02:13:31 +00:00
gad
22c6f74458 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
gad
db8a4ef7a9 Explicitly wrap two long-ish linesi of code, to make them easier to read. 2004-03-27 21:59:54 +00:00
gad
153d99ec1c 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
gad
ad1098e739 Move the 'f' case so it shows up in the right place, alphabetically. 2004-03-27 21:40:04 +00:00
gad
a0a0eebb33 Update the date on the man page, since this the previous change added
a few new options.
2004-03-27 18:26:40 +00:00
gad
2b815e77ed 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
ru
e07a59b2f0 Avoid the manpage layering violation and low-level implementation
details of libkvm, and just tell what the getbootfile(3) function
will return, by using the text from netstat(1) and dmesg(8).
2004-03-26 08:54:27 +00:00
ru
482875344b - Remove references to /dev/kmem -- ps(1) utilizes the
sysctl(3) interface in kvm(3).
- Document the correct default when no -N is specified.
- Remove stale reference to /var/db/kvm_kernel.db.
- Remove stale reference to /var/run/dev.db.
2004-03-26 08:29:38 +00:00
tjr
6672d6d2e0 Document incorrect handling of multibyte characters. 2004-03-21 11:24:06 +00:00
gad
abf08cd271 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
gad
5091cee4e6 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
johan
c1045205c1 style.Makefile:
Use WARNS?= instead of WARNS=
2004-02-23 20:05:14 +00:00
deischen
d06c271267 Allow the -H option to show threads when selecting by uid, tty,
and pid.
2004-02-22 17:59:31 +00:00
jmallett
6f2d2e36e0 MFp4 @46705:
Support "uprocp" exactly like "paddr" with the former having been
documented in the manual but not implemented.

PR:		42484
2004-02-08 23:57:19 +00:00
cperciva
681fd029d8 Bring ps.1 up to date with changes in the past seven years:
* Remove mention of '>', 'A', and 'S' states
* Mention 'W' state.
* List 'J' state in the correct location.
* Sync with flags in sys/proc.h

Approved by: rwatson (mentor)
MFC after: 7 days
2004-01-21 16:25:36 +00:00
ru
1c23ef339b mdoc(7): Use the new feature of the .In macro. 2003-09-08 19:57:22 +00:00
harti
a45a05930d Implement the nwchan keyword that has been in the man page, but was
not implemented. This is just handy if you want to ddb the address
some process is waiting on.
2003-08-13 07:35:07 +00:00
brueffer
190f128893 Clarify that the 'state' information consists of characters, not
only letters (e.g. IWs+)

PR:		55221
Submitted by:	Rich Morin <rdm@cfcl.com>
MFC after:	3 days
2003-08-05 10:31:28 +00:00
markm
aafc494847 Get this area compiling with the highest WARNS= that it works with.
Obsolete WFORMAT= junk also removed where possible.

OK'ed by:	obrien
Tested on:	sparc64, alpha, i386
2003-06-13 07:04:02 +00:00
scottl
3b2e1bb375 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
charnier
75dc23e15b add section name to .Xr 2003-06-08 09:48:39 +00:00
markm
bc6b9b68d5 Fix long constant usage for i386.
Tested by:	Joe Marcus Clarke <marcus@marcuscom.com>
2003-05-03 20:52:48 +00:00
markm
0bdf7b1ca4 Fix a bazillion warnings. This makes almost the whole of src/bin/*
WARNS=6, std=c99 clean.

Tested on:	i386, alpha
2003-05-03 16:39:34 +00:00
obrien
675505de16 fmt.c has a comparison between signed and unsigned that is unclear how
to properly fix.
2003-05-02 01:05:05 +00:00
schweikh
eb8fd40b31 Fix references to non-existing or obsoleted man pages.
PR:	docs/51480 (only a small part)
Submitted by:	Diomidis D. Spinellis <dds@aueb.gr>
2003-04-30 19:18:50 +00:00
charnier
1315d25026 Revert the zombie part of previous commit 2003-04-15 18:49:20 +00:00
charnier
26efa7aed0 Correct style bugs. Don't skip zombies in cputime(), according to Bruce,
zombie CPU times are valid. Adjust array size in strftime(3).

Submitted by:	Bruce
2003-04-14 19:51:36 +00:00
tjr
72859c819a Display residency and sleep times (re and sl fields) larger than 127 as 127.
This is what the manual page says ps should do, and what OpenBSD and NetBSD do.
Based on a patch from Ken Stailey.

PR:		27433, 46232
2003-04-12 10:39:56 +00:00
sobomax
09fd7460b1 Fix slight disorder that broke sorting. Put in bold warning about the
fact that in this case order matters.

Submitted by:	Peter Edwards <pmedwards@eircom.net>
2003-02-05 19:22:39 +00:00
charnier
923572be6a 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
jmallett
73809496b4 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
jmallett
0c8d64a2c4 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
jmallett
40b68c17b2 Refer to the process label as proclabel, as there is a function called label,
and that's what these locals were called before.
2003-01-18 03:31:30 +00:00
ru
301b96498b Fixed the abuses of .Ql visible on stderr in troff mode.
PR:		docs/37176
2002-12-23 16:04:51 +00:00
tmm
a383c7b134 The hw.availpages sysctl has an unsigned long value now, fix the retrieval
to match that.
2002-11-01 23:26:20 +00:00
tjr
bf0839bdc9 Do not print a header line if it would be empty; required by 1003.1-2001. 2002-10-31 13:41:37 +00:00
rwatson
c1f79de8c7 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
bde
84d13cfde4 Oops, the previous version was a last minute test version with off_t
replaced by int instead of size_t.

Spotted by:	fanf
2002-10-03 17:19:36 +00:00
bde
6e48538b41 Use a non-bogus type for representing the values of offsets in structs.
off_t is for offsets in files, and it is signed so it was no better
than the original type of int for avoiding warnings from broken lints,
except accidentally on machines like i386's where size_t is smaller
than off_t.
2002-10-03 15:00:07 +00:00
jhb
b79961de95 Catch up to SMTX -> SLOCK changes. 2002-10-02 20:33:52 +00:00
jmallett
218fa5fb98 List valid keywords, ala kill(1), rather than the csh builtin kill, which
tells people to type kill -l, when no valid ones are specified.

Sponsored by:	Bright Path Solutions
MFC after:	4 days
2002-09-27 01:44:30 +00:00
jmallett
0400410a48 Ala kill(1), tell people to type 'ps -L' for a list of format keywords.
Sponsored by:	Rachel Hestilow <rachel@jerkcity.com>
MFC after:	2 weeks
2002-09-27 01:40:30 +00:00
jmallett
6d599b2b06 Rename new PLONG type to PGTOK as the conversion is more important than the
size (which is mostly undefined anyway).

Submitted by:	bde
2002-09-17 17:13:52 +00:00
jmallett
b561096e47 Conglomerate printing of ps_pgtok'd data into a PLONG type. I couldn't think
of a better name, except PINT, but I decided to go with assuming LONG to
be safe, rather than assuming INT.
2002-09-17 02:52:44 +00:00
jmallett
fece93f6bd Perform keyword.c:1.27 properly, implement -orss in the New World Order of
ps(1) formatting, using pgtok() to get the value in K, rather than printing
it in pages.  This is consistent with behaviour before keyword.c:1.26 (et al)
which exists in STABLE today, and which uses the same metric as VSZ.

Submitted by:	bde
2002-09-16 20:19:51 +00:00
jmallett
939d493b8a Remove some NOTINUSE stuff. Good housekeeping. 2002-09-16 20:06:04 +00:00
peter
c8f83170c0 Do not risk using the kernel pgtok() which assumes the page size is
constant.
2002-09-13 07:13:33 +00:00
jmallett
26df3d636e 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
trhodes
9618da3e35 s/filesystem/file system/ as discussed on -developers 2002-08-21 17:32:44 +00:00
ru
9c0fb519a7 mdoc(7) police: whitespace nits. 2002-08-09 10:49:50 +00:00
bde
f340aa750e Fixed a printf format error that was fatal on alphas. Adding WFORMAT=0
to the Makefile didn't affect this bug because WFORMAT only controls
higher- level format checking (not the -Wformat that is implicit in
-Wall).

Fixed a nearby printf format error that was benign and 3 nearby style bugs.
2002-07-11 17:28:29 +00:00
dillon
3adf63f81d err() is documented as allowing NULL for the format string but GCC isn't
happy about it any more so change the usage to make buildworld work again.
2002-07-10 20:44:55 +00:00
jmallett
15fec8826f Bring back WFORMAT=0. 2002-07-08 15:48:39 +00:00
robert
47f9f58c0a - 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
jmallett
b246443071 Make printval() take a 'void *' thus negating any assumptions the compiler
may try to make about the alignment of the dereferenced datum.
2002-07-07 21:45:59 +00:00
mike
27f3da3573 Don't depend on pollution in <limits.h> for the definition of
<stdint.h> macros.
2002-07-05 15:58:27 +00:00
obrien
f6f518b207 Consistently use FBSDID 2002-06-30 05:15:05 +00:00
sobomax
8e683e45ef 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
jmallett
d40b17fd5d ps(1) appeared in v4
Submitted by:	grog
2002-06-10 22:48:51 +00:00
jmallett
dcf74a7fe1 Note early appearence of some commands. These actually appeared in PWB, but
it seems we don't have a macro for that yet, so list them in the first UNIX
release since then that we have a .At for: v7.
2002-06-10 05:03:20 +00:00
jmallett
ef26e821fb Allow whitespace to act as a delimiter in the keywords list given to the -o,
again, but also allow it in the user-specified header, too.  This is far more
backwards compatible and SUSv3-happy than allowing only comma to seperate the
keywords list.

Submitted by:	tjr
2002-06-08 18:11:52 +00:00
bde
fa2a4fdbfc Fixed unsorting. 2002-06-08 06:49:15 +00:00
jmallett
93d0005574 Don't say that the list of formats can be space delimited, it no longer can be.
Mention that more than one -o will concatenate formats.

Submitted by:	Jun Kuriyama <kuriyama@imgsrc.co.jp>
2002-06-08 05:47:46 +00:00
jmallett
01f3abcecd Back out previous back out of previously correct code.
Double-plus-pointy-hat to:	jmallett
Submitted by:			bde
2002-06-07 01:14:05 +00:00
jmallett
865fcaca35 Remove tunables to hide warnings that no longer exist. 2002-06-07 00:01:00 +00:00
jmallett
95a388cd9a Cast to long to match format. Hidden by revision 1.18 of Makefile. 2002-06-07 00:00:29 +00:00
jmallett
d11731ff43 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
jmallett
becd81c4a9 Implement a SUSv3-ignorant but "time"-similar format for "etime", elapsed
run time (NOT cpu time).  cputime() and elapsed() both need to honour SUSv3
now.
2002-06-06 21:18:37 +00:00
jmallett
b00060629b sysctlbyname(3) returns -1 on failure, not any other value < 0. 2002-06-06 20:59:15 +00:00
jmallett
b9515c4b9c Support the SUSv3 `rgroup' format.
Clean up some local style bogons.
2002-06-06 20:42:16 +00:00
jmallett
7916563c61 Cast arg_max to size_t when comparing it (times 4, plus 1) against SIZE_MAX. I
was worried about truncation of arg_max by this cast, but if it gets truncated,
we know it'll obviously be greater than SIZE_MAX anyway.

Big pointy hat to:	jmallett
Submitted by:		keramida
2002-06-06 20:29:39 +00:00
jmallett
562b4c0250 SUSv3 conform on the "comm" and "args" formats, and make correct the "command"
format, since it's BSDlike, and "comm" is actually different.
2002-06-06 20:21:47 +00:00
jmallett
c22ab1edea Refer to the command format by its SUSv3 name (comm), and list command as an
alias.
2002-06-06 18:10:12 +00:00
jmallett
3afc0fe273 As per behaviour on SVR4 systems, to allow any desirable type of header in the
override, seperate by comma (',') only, rather than any type of whitespace
(the literal space character (' ') had already been removed from this list).

This allows things like:
miamivice# ps -opid='Process
> Identifier'
Process
Identifier
              1350
              1445
              1450

To work.
2002-06-06 18:04:46 +00:00
jmallett
e24090eb3a 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
jmallett
9b75b96530 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
jmallett
c2f44f7a37 Support the 'comm' keyword, which is equivalent to our 'command', but
specified by SUSv3.
2002-06-05 02:05:24 +00:00
jmallett
399bb45a09 A space cannot be a header string seperator it appears given the SUSv3
description of ps(1), which uses them.  I question whether newline and tab
can be either, but I'm not touching them.  Yet.
2002-06-05 02:01:46 +00:00
jmallett
d6bbfbe40b To comply with SUSv3, duplicate the variable contents for each given format,
so that multiple -ovar=header lines do not overwrite eachother.

This means that ps -ouser=USERNAME -ouser=WHO would now possibly print:
USERNAME WHO
juli     juli

Whereas before it would be:
WHO WHO
juli juli
2002-06-05 01:58:36 +00:00
jmallett
6cb17fa895 Returning NULL here if malloc(3) fails is silly, at this point in the codepath
we have't malloc(3)'d nearly as much as we probably will, so errx(3) away,
instead of waiting for something to fail yet again later on.
2002-06-05 01:36:30 +00:00
jmallett
b34dd0148d Remove an XXX comment that seems to be a tiny bit no longer pertinent. This
function seems to do the right thing, and is not a "stub", and whoever "marc"
is, he's had plenty of time to do "the real one", so don't wait around for
him any longer.
2002-06-05 01:33:54 +00:00
jmallett
66d6aa72a5 Use of zero here meant many things, NULL, '\0' (NUL), and 0. Sort it out. 2002-06-05 01:32:21 +00:00
jmallett
4dd8bac65f Use a const char * where it is meant to be used. There's no reason to try
to discard the const qualifier here.
2002-06-05 01:02:13 +00:00
jmallett
3139a6b754 Duplicate the pointer to the string containing the header so it does not get
frobbed when/if the pointer it is actually a part of gets freed.
2002-06-05 01:01:20 +00:00
tjr
b3775d9e40 Respect setting of the COLUMNS environment variable (SUSv3) 2002-06-04 10:20:10 +00:00
joe
40c0cc2b5f The sysctl has changed from 'kern.ps_showallprocs' to
'security.bsd.see_other_uids'.
2002-05-16 11:51:05 +00:00
trhodes
56036d2623 Consistancy check s/file system/filesystem/
Reviewed by:	brian
2002-05-16 01:57:20 +00:00
joe
36c976074e Replace /kernel with /boot/kernel/kernel.
PR:		docs/37757
Submitted by:	Hiten Pandya <hiten@uk.FreeBSD.org>
2002-05-09 11:47:42 +00:00
jmallett
0871762074 Check for possible overflow from sysconf _SC_ARG_MAX and error out in a
correct manner.  Revert my incorrect change to use err(3) for malloc(3)
failing.  Use a size_t variable to store the size of the argument buffer
we allocate, and remove silly casts as the result of having this around.
Modify the math in some of the paranoid checks for buffer overflow to
account for the fact we now are dealing with the actual size of the
buffer.  Remove the static qualifier for arg_max, and the bogus setting
of it to -1.

Include <limits.h> for the definitions we use to check for possible
overflows.

Submitted by:	bde
2002-05-05 04:42:50 +00:00