Commit Graph

128 Commits

Author SHA1 Message Date
Bryan Drewery
13767130c7 Add -J to filter by matching jail IDs and names.
-J 0 can be used to show only host processes.

Patch partially based on work by bz@

PR:		bin/78763
MFC after:	2 weeks
Relnotes:	yes
2014-05-02 15:05:47 +00:00
John Baldwin
9f0b6e5e27 - Move 'showthreads' check out of fmt.c.
- Update shadow copy of fmt_argv() prototype in w.c and fix calls for
  additional parameter.
2013-01-19 00:21:55 +00:00
John Baldwin
1c67ef129f Include the thread name along with the command name when displaying the
command name of a thread from a multi-threaded process that doesn't have
an available argument list (such as kernel processes) and threads display
is enabled via -H.

Reviewed by:	alfred, delphij, eric@vangyzen.net
MFC after:	1 week
2013-01-18 18:24:40 +00:00
Pawel Jakub Dawidek
64b0bf0bb6 Use kern.max_pid sysctl to obtain maximum PID number instead of using local
define.

Reviewed by:	jhb
2012-12-12 15:45:03 +00:00
Ed Maste
4285666880 Avoid passing uninitialized stack to addelem() if called with an empty arg.
PR:		bin/171174
2012-08-29 21:38:34 +00:00
Ulrich Spörlein
38494eff98 Spelling fixes for bin/ 2012-01-07 16:10:23 +00:00
Mikolaj Golub
57c87bfabb No need in procfs(5).
MFC after:	2 weeks
2011-11-22 21:14:46 +00:00
Edward Tomasz Napierala
1d1143ec27 Make ps(1) automatically size its column widths. 2011-09-29 06:31:42 +00:00
Ulrich Spörlein
bf2fe08eea Fix some typos under bin/
Found by:	codespell
2011-05-22 14:03:46 +00:00
Edward Tomasz Napierala
649fde88ff Get rid of DSIZ; instead just call the sizing function if provided. 2011-04-12 20:10:15 +00:00
Rebecca Cran
c08dcaf147 Initialize the execfile argument to NULL instead of _PATH_DEVNULL. This allows the -M option to be used without specifying -N.
PR:	bin/138146
Approved by:	rrs (mentor)
MFC after:	3 days
2010-02-08 21:23:48 +00:00
Brian Somers
aa14b5ab89 Add the -d switch to the usage message.
Submitted by:	Emil Mikulic - emil at dmr dot ath dot cx
Approved by:	re (kib)
MFC after:	1 week
2009-07-23 10:20:12 +00:00
Brian Somers
8ba7efdad8 Remove redundant whitespace 2009-05-18 01:45:52 +00:00
Brian Somers
044fce530f Add a -d option to ps to display descendant info with the output.
This is similar to linux's -H (or -f) switch.

MFC after:	3 weeks
2009-05-17 04:00:43 +00:00
Kevin Lo
0c025af962 Remove unnessasary cast 2008-07-18 14:55:22 +00:00
John Baldwin
8a529f590f Teach ps(1) to parse pts TT values (i.e. '0', '1') for the -t flag.
MFC after:	1 week
Reported by:	kris
2007-11-08 22:31:28 +00:00
Julian Elischer
7ab24ea3b9 Introduce a way to make pure kernal threads.
kthread_add() takes the same parameters as the old kthread_create()
plus a pointer to a process structure, and adds a kernel thread
to that process.

kproc_kthread_add() takes the parameters for kthread_add,
plus a process name and a pointer to a pointer to a process instead of just
a pointer, and if the proc * is NULL, it creates the process to the
specifications required, before adding the thread to it.

All other old kthread_xxx() calls return, but act on (struct thread *)
instead of (struct proc *). One reason to change the name is so that
any old kernel modules that are lying around and expect kthread_create()
to make a process will not just accidentally link.

fix top to show  kernel threads by their thread name in -SH mode
add a tdnam formatting option to ps to show thread names.

make all idle threads actual kthreads and put them into their own idled process.
make all interrupt threads kthreads and put them in an interd process
(mainly for aesthetic and accounting reasons)
rename proc 0 to be 'kernel' and it's swapper thread is now 'swapper'

man page fixes to follow.
2007-10-26 08:00:41 +00:00
Jeff Roberson
b61ce5b0e6 - Move all of the PS_ flags into either p_flag or td_flags.
- p_sflag was mostly protected by PROC_LOCK rather than the PROC_SLOCK or
   previously the sched_lock.  These bugs have existed for some time.
 - Allow swapout to try each thread in a process individually and then
   swapin the whole process if any of these fail.  This allows us to move
   most scheduler related swap flags into td_flags.
 - Keep ki_sflag for backwards compat but change all in source tools to
   use the new and more correct location of P_INMEM.

Reported by:	pho
Reviewed by:	attilio, kib
Approved by:	re (kensmith)
2007-09-17 05:31:39 +00:00
Ruslan Ermilov
a89237ae95 Sync program's usage() with manpage's SYNOPSIS. 2005-02-09 17:37:39 +00:00
Christian S.J. Peron
d8654c644a Use statfs instead of getmntinfo(). This will make the procfs checks
play nicer in prisons. It also simplifies things.

Reviewed by:	rwatson
Bumped into by:	Jilles Tjoelker
2004-11-19 16:11:54 +00:00
Christian S.J. Peron
a951d1f83b Currently if the user specifies -e and procfs is not mounted on /proc,
printing of the process environment will fail silently.

-define a function which will check to see if procfs is mounted on /proc
-Implement this test if the user specified -e
-If procfs is not mounted on /proc and -e was specified, print a warning.
 informing the user that procfs(5) is required.

Reviewed by:	wes, rwatson
2004-11-14 19:30:02 +00:00
Ruslan Ermilov
832b0b55ac Removed bitrot. 2004-11-13 17:12:22 +00:00
Garance A Drosehn
f2fbfae6b0 Improve checking for `ps -t <dev>', and give better error messages when
an invalid <dev> is specified.  Aside:  It turns out that the S_ISCHR()
check is true for almost every device that we have (not just tty's).
2004-06-27 22:56:58 +00:00
Garance A Drosehn
bd6233fd5d Fix a bug I introduced by some last-minute changes in -r 1.102. I ended
up checking the wrong variable for NULL.

Submitted by:	bde
2004-06-24 03:15:18 +00:00
Garance A Drosehn
23b8efad7a Rework the logic for `-t <tty>', such that it accepts "ttyp0" and "console",
in addition to "/dev/ttyp0" or "p0"  and  "/dev/console" or "co".
2004-06-24 01:57:59 +00:00
Garance A Drosehn
bdf8ab4692 Change "struct varent" to use the standard queue(8) macros, instead of
using it's own version of the same basic algorithm.

Submitted by:	part by Cyrille Lefevre, part of it done by me
2004-06-23 23:48:09 +00:00
Garance A Drosehn
dd693acf27 Add a check for defunct processes in saveuser(), so the output for "args"
(aka "command") will display "<defunct>", as does the output from "comm"
for those processes.  Also do better checking for malloc() failures.

Submitted by:	Cyrille Lefevre
2004-06-23 21:17:25 +00:00
Garance A Drosehn
31172f6e1b Include the `-c' option in the usage() message.
Submitted by:	Cyrille Lefevre
2004-06-23 11:40:56 +00:00
Garance A Drosehn
b4b243242b In the sorting routine, sort by thread-id if two processes have the same PID.
Submitted by:	Cyrille Lefevre
2004-06-23 11:28:17 +00:00
Garance A Drosehn
4bac4483db Have the main() routine calculate %CPU and (if needed) memory information
when copying per-process info before starting to sort the list.  This way,
sort-by-CPU or sort-by-memory will only calculate values once-per-process,
instead of twice-per-comparison.  Also take advantage of this to simplify
the pscomp() routine.
2004-06-20 21:25:10 +00:00
Garance A Drosehn
ecbb06f865 Try to change the isdigitch() macro to something that Bruce won't roll
his eyes at quite so much...  (actually someone else pointed this out
to me a long time ago, but apparently I never fixed it)
2004-06-01 23:27:11 +00:00
Garance A Drosehn
c23b00b7ca A few more style-fixes from Bruce. The only non-cosmetic change
is to drop a call to setuid() which has not been needed for years.

Noticed by:	bde
2004-06-01 22:19:16 +00:00
Garance A Drosehn
a9626fb3b4 Since I'm not ready to add the non-standard ADD_PS_LISTRESET feature,
remove the #ifdef for it for now.  I might add the feature for real at
some later date, there isn't much reason for the #ifdef for now.
2004-06-01 19:00:42 +00:00
Garance A Drosehn
251130839b Make a few style-istic improvements to the previous commits.
Noticed by:	bde
2004-06-01 18:12:04 +00:00
Garance A Drosehn
de1702f459 Fix so `ps' catches and complains about null-values specified for a
process id, instead of using pid==0.  Ie, `ps -p 12,' and `ps -p ,12'
are now errors (instead of being treated like `ps -p 0 -p 12').

Noticed by:	Cyrille Lefevre on freebsd-arch
2004-06-01 03:01:51 +00:00
Garance A Drosehn
bf46a3bf10 Additional tiny adjustment to kludge-option processing so `ps t p0'
is treated like `ps -t p0', instead of changing it to `ps -T p0'.
Note that `ps t' is still changed to `ps -T', since that is one of
the main reasons for this kludge processing...

Noticed by:	Jilles Tjoelker on freebsd-arch
2004-06-01 02:31:44 +00:00
Garance A Drosehn
c675340a5c Rewrite the kludge-option processing to improve how it handles a few
more special situations.  This is the code which process `ps blah',
when "blah" does not include a leading '-'.

This change also removes a long-undocumented BACKWARD_COMPATIBILITY
compile-time option, where:
     ps -options arg1 arg2
(with no '-' on "arg1" and "arg2") was treated as:
    ps -options -N arg1 -M arg2

This also changes `ps' to check for any additional arguments after
processing all the '-'-options, and attempt to use those arguments as
a pid or pidlist.  If an extra argument is not a valid pidlist, then
`ps' will print an error and exit.  This seems a more generally useful
extension of the kludge-option processing than the -N/-M behavior, and
has fewer confusing side-effects.

Reviewed by:	freebsd-arch
2004-06-01 02:03:21 +00:00
Garance A Drosehn
259fcfacc4 Add the 'sid' info to the output of `ps -j', to make up for the 'sess'
(session-pointer) info which was dropped from `ps' earlier in 5.x.

PR:		bin/59423
Submitted by:	Jilles Tjoelker
2004-05-23 21:35:35 +00:00
Garance A Drosehn
2631c7774f Fix the kludge-old-options processing so `ps tpt' will be treated the
same as `ps -tpt', instead of being changed into `ps -tpT'.

PR:		bin/52489
Submitted by:	Jilles Tjoelker
MFC after:	1 week
2004-05-23 21:21:07 +00:00
Garance A Drosehn
7bd421650b Change `ps' to use the KERN_PROC_RGID and KERN_PROC_SESSION options
(if trying to match only one real-group or one session-id), now that
those options are implemented in src/sys/kern/kern_proc.c (v1.203).

PR:		bin/65803  (a very tiny piece of the PR)
Submitted by:	Cyrille Lefevre
2004-05-22 23:13:58 +00:00
Mark Murray
6195fb4102 Remove clause 3 from the UCB licenses.
OK'ed by:	imp, core
2004-04-06 20:06:54 +00:00
Garance A Drosehn
b193355dc4 Drop the include of <stdint.h>, since r1.84 removed references of intmax_t. 2004-04-04 17:43:48 +00:00
Garance A Drosehn
9bf69950e1 Add back the `-e' option, which was mistakenly dropped when cleaning
up the PS_ARGS string in revision 1.69 (and which was apparently not
missed by anyone...).
2004-04-04 17:15:44 +00:00
Garance A Drosehn
d822163f3b Give a name of 'l' (list) to the union in struct listinfo. This is
because some compilers (such as gcc 2.95.4) do not support having an
unnamed union for a field in a struct.
2004-04-04 04:41:51 +00:00
Garance A Drosehn
0b42be7cb7 Switch to using strtoul() for parsing a potential UID or GID, which gets
this to correctly handle UID's and GID's larger than 2147483647.

Noticed by:	bde
MFC after:	1 week
2004-03-30 04:20:33 +00:00
Garance A Drosehn
f35e071573 Bruce would really like the prototype for fmt() to be split across lines
this way (although I still think it "looks weird"...).

Requested by:	bde
MFC after:	1 week
2004-03-30 02:02:40 +00:00
Garance A Drosehn
ba50b0e03a Minor style fixes, mostly adding indent-protection on some comment-blocks.
Noticed by:	bde
MFC after:	1 week
2004-03-30 01:59:22 +00:00
Garance A Drosehn
5bd7b1f3c0 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
Garance A Drosehn
c46bb4b3ff Oops. Remove some ';'s in #defines added by a previous update.
Noticed by:	bde
2004-03-29 03:03:28 +00:00
Garance A Drosehn
c7910c3ae3 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