History log of /freebsd-10.1-release/bin/ps/print.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 272461 02-Oct-2014 gjb

Copy stable/10@r272459 to releng/10.1 as part of
the 10.1-RELEASE process.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

# 260195 02-Jan-2014 trasz

MFC r256838:

Don't test arrays for being NULL.

Sponsored by: The FreeBSD Foundation


# 256281 10-Oct-2013 gjb

Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation


# 238488 15-Jul-2012 jilles

ps: Fix memory leak when showing start/lstart for swapped-out process.

Spotted by: scan-build (uqs)


# 230287 17-Jan-2012 ed

Remove unused variables.

Simply annotate the function parameters with __unused, instead of adding
the ve-variables. This makes the code build with GCC 4.7 and -Werror.


# 226939 30-Oct-2011 trasz

For processes with no controlling terminal, display "-" in the TTY column
instead of "?".

Submitted by: arundel


# 225868 29-Sep-2011 trasz

Make ps(1) automatically size its column widths.


# 225847 28-Sep-2011 ed

Get rid of major/minor number distinction.

As of FreeBSD 6, devices can only be opened through devfs. These device
nodes don't have major and minor numbers anymore. The st_rdev field in
struct stat is simply based a copy of st_ino.

Simply display device numbers as hexadecimal, using "%#jx". This is
allowed by POSIX, since it explicitly states things like the following
(example taken from ls(1)):

"If the file is a character special or block special file, the
size of the file may be replaced with implementation-defined
information associated with the device in question."

This makes the output of these commands more compact. For example, ls(1)
now uses approximately four columns less. While there, simplify the
column length calculation from ls(1) by calling snprintf() with a NULL
buffer.

Don't be afraid; if needed one can still obtain individual major/minor
numbers using stat(1).


# 224199 18-Jul-2011 bz

Rename ki_ocomm to ki_tdname and OCOMMLEN to TDNAMLEN.
Provide backward compatibility defines under BURN_BRIDGES.

Suggested by: jhb
Reviewed by: emaste
Sponsored by: Sandvine Incorporated
Approved by: re (kib)


# 223086 14-Jun-2011 trasz

Add "gid" and "group" keywords to display the effective group ID
and effective group name. Also, add "egid", "egroup" and "euid" aliases.

PR: bin/146331
Submitted by: Jeremie Le Hen <jeremie at le-hen dot org>


# 219972 24-Mar-2011 trasz

Add proper width calculation for time fields (time, cputime and usertime).
This fixes the ugly overflow in "ps aux" output for "[idle]".


# 219967 24-Mar-2011 trasz

Make "LOGIN" and "CLASS" columns width scale properly instead of wasting space.


# 219713 17-Mar-2011 kib

Implement the usertime and systime keywords for ps, printing the
corresponding times reported by getrusage().

Submitted by: Dan Nelson <dnelson allantgroup com>
MFC after: 1 week


# 219307 05-Mar-2011 trasz

Export login class information via kinfo and make it possible to view
it using "ps -o class".


# 217192 09-Jan-2011 kib

Move repeated MAXSLP definition from machine/vmparam.h to sys/vmmeter.h.
Update the outdated comments describing MAXSLP and the process
selection algorithm for swap out.

Comments wording and reviewed by: alc


# 205271 17-Mar-2010 jmallett

o) Add a keyword to displaying elapsed time in integer seconds, "etimes".
o) Give slightly better (i.e. any) documentation of the format of "etime".

Reviewed by: jilles


# 192688 24-May-2009 jilles

Fix elapsed (etime) field for swapped out processes in ps:
show '-' instead of time since the Epoch.

PR: bin/123069
Submitted by: Vladimir Kozbin
Approved by: ed (mentor)
MFC after: 3 weeks


# 192239 17-May-2009 brian

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


# 189078 26-Feb-2009 attilio

[1] When showing threads, the thread name just appears if the comm
label is choosen as last printout (ucomm suffers of this such bug
too). That bug is caused by the fact that the fixed size of
printout doesn't leave enough space for them to be printed out.
Implement ucomm and comm commands with a dynamic size lenght for
buffers.

[2] On AMD64 architecture pointers don't have enough chars space to
be shown (8 chars while they need 16). Fix them by providing
a variadic space so that it fits well on both 64 and 32 bits
architectures.

[3] Check a return value of malloc() that wasn't checked before.

PR: bin/128841, bin/128842
Reviewed by: jhb, emaste
Sponsored by: Sandvine Incorporated


# 184925 13-Nov-2008 emaste

Fix whitespace.


# 173004 26-Oct-2007 julian

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.


# 172207 17-Sep-2007 jeff

- 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)


# 155876 21-Feb-2006 cognet

For pts, print the pts number, instead of the full name. As it was, we ended
up always printing "pts".

Submitted by: Michal Mertl <mime at traveller dot cz>


# 132433 20-Jul-2004 tjr

Use warn() instead of perror().


# 131215 27-Jun-2004 gad

Change the "rtprio" format so it prints an informative string for
the PRI_ITHD case (instead of just printing the digit '1').

Submitted by: Cyrille Lefevre


# 130999 23-Jun-2004 gad

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


# 130975 23-Jun-2004 gad

Avoid padding the value of "ucomm" when it is the last column in the line.

Submitted by: Cyrille Lefevre


# 130974 23-Jun-2004 gad

Make sure the value of "upr" (scheduling priority on return from system call)
is scaled in the same way that "pri" (scheduling priority) is scaled.

Submitted by: Cyrille Lefevre


# 130856 21-Jun-2004 gad

Have `ps' return the cputimes for zombies, with the assumption that
kvm_getprocs() will provide useful information if it can, or *it*
will provide a zero value if it can not find something appropriate.

Submitted by: bde


# 130830 20-Jun-2004 gad

Add the `-O emul' format option, which prints the name of the system-call
emulation environment the process is in. "emul" as a keyword is picked
up from OpenBSD.

PR: bin/65803
Submitted by: Cyrille Lefevre


# 130828 20-Jun-2004 gad

From SUSv3:
Any [standard output] field need not be meaningful in all
implementations. In such a case a hyphen ('-') should be
output in place of the field value

So have the `-O label' option print out the string " -" if the
process has no label.

Approved by: Silence from rwatson and green (when asked in March...)


# 127958 06-Apr-2004 markm

Remove clause 3 from the UCB licenses.

OK'ed by: imp, core


# 127512 28-Mar-2004 gad

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)


# 118857 13-Aug-2003 harti

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.


# 113524 15-Apr-2003 charnier

Revert the zombie part of previous commit


# 113485 14-Apr-2003 charnier

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


# 113395 12-Apr-2003 tjr

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


# 110391 05-Feb-2003 charnier

Display elapsed time (-o etime) using [[dd-]hh:]mm:ss, which according to
Solaris man page is the POSIX way.

Reviewed by: jmallett


# 109504 18-Jan-2003 jmallett

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.


# 109460 18-Jan-2003 jmallett

Refer to the process label as proclabel, as there is a function called label,
and that's what these locals were called before.


# 106251 31-Oct-2002 tjr

Do not print a header line if it would be empty; required by 1003.1-2001.


# 105831 23-Oct-2002 rwatson

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


# 104388 02-Oct-2002 jhb

Catch up to SMTX -> SLOCK changes.


# 103497 17-Sep-2002 jmallett

Rename new PLONG type to PGTOK as the conversion is more important than the
size (which is mostly undefined anyway).

Submitted by: bde


# 103438 17-Sep-2002 jmallett

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.


# 103422 16-Sep-2002 jmallett

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


# 103274 13-Sep-2002 peter

Do not risk using the kernel pgtok() which assumes the page size is
constant.


# 99785 11-Jul-2002 bde

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.


# 99547 07-Jul-2002 jmallett

Make printval() take a 'void *' thus negating any assumptions the compiler
may try to make about the alignment of the dereferenced datum.


# 99110 30-Jun-2002 obrien

Consistently use FBSDID


# 97971 06-Jun-2002 jmallett

Cast to long to match format. Hidden by revision 1.18 of Makefile.


# 97966 06-Jun-2002 jmallett

Use a global `now' variable for the current time, and initialise it at
startup, right after calling setlocale(3).


# 97965 06-Jun-2002 jmallett

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.


# 97961 06-Jun-2002 jmallett

Support the SUSv3 `rgroup' format.

Clean up some local style bogons.


# 97958 06-Jun-2002 jmallett

SUSv3 conform on the "comm" and "args" formats, and make correct the "command"
format, since it's BSDlike, and "comm" is actually different.


# 97877 05-Jun-2002 jmallett

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


# 97843 04-Jun-2002 jmallett

Use a const char * where it is meant to be used. There's no reason to try
to discard the const qualifier here.


# 91089 22-Feb-2002 markm

ANSIfy.


# 91028 21-Feb-2002 dillon

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>


# 90878 18-Feb-2002 imp

Fixed divots that I created when I moved prototypes of group_from_gid
and user_from_uid to grp.h and pwd.h. Update the man pages.

Submitted by: David Malone
Pointy hat to: imp


# 90740 16-Feb-2002 dillon

When blocked on a mutex, display the mutex name via the wchan string field
so we can at least tell the difference between being blocked in Giant
and being blocked in some other mutex.


# 90143 03-Feb-2002 markm

WARNS=4 fixes (incomplete, so set NO_WERROR), and lots of extra
cleanup courtesy of automatic checking (lint).


# 90110 02-Feb-2002 imp

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.


# 89389 15-Jan-2002 sobomax

Add missed includes.

Reviewed by: md5


# 86922 26-Nov-2001 green

Add LOMAC options (the "Z" flag in both cases) to display extra information
in ls(1) and ps(1).

Sponsored by: DARPA, NAI Labs


# 83366 12-Sep-2001 julian

KSE Milestone 2
Note ALL MODULES MUST BE RECOMPILED
make the kernel aware that there are smaller units of scheduling than the
process. (but only allow one thread per process at this time).
This is functionally equivalent to teh previousl -current except
that there is a thread associated with each process.

Sorry john! (your next MFC will be a doosie!)

Reviewed by: peter@freebsd.org, dillon@freebsd.org

X-MFC after: ha ha ha ha


# 83280 10-Sep-2001 peter

UPAGES as a constant is gone in KSE. We are going to have to trust
and/or fix ki_rssize.


# 82268 24-Aug-2001 peter

On today's kernels masking with ~KERNBASE is turning out to be less
than useful. It still hits at least 8 digits. Adjust for reality.

This is still not satisfactory for the alpha if you add "-O paddr".


# 78363 16-Jun-2001 tegge

Check for the PS_SINTR flag in the right field of struct kinfo_proc
(ki_sflag).


# 76245 03-May-2001 markm

Depollute headers now that the VM headers DTRT.


# 76168 01-May-2001 markm

Compensate for header dethreading.


# 73369 02-Mar-2001 ache

Small optimization: set use_ampm only when needed


# 73367 02-Mar-2001 ache

Use AM/PM time only when available in locale


# 72377 11-Feb-2001 jake

Catch up to new priority interface.


# 72343 11-Feb-2001 ache

Use decimal point from locale


# 71578 24-Jan-2001 jhb

- Catch up to new proc flags.


# 69896 12-Dec-2000 mckusick

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.


# 69372 29-Nov-2000 jhb

Introduce a 'mtxname' keyword that displays the current mutex that a
process is blocked on or '-'.


# 66417 28-Sep-2000 kris

No need to work around SCCS variable expansion any more.


# 65557 06-Sep-2000 jasone

Major update to the way synchronization is done in the kernel. Highlights
include:

* Mutual exclusion is used instead of spl*(). See mutex(9). (Note: The
alpha port is still in transition and currently uses both.)

* Per-CPU idle processes.

* Interrupts are run in their own separate kernel threads and can be
preempted (i386 only).

Partially contributed by: BSDi (BSD/OS)
Submissions by (at least): cp, dfr, dillon, grog, jake, jhb, sheldonh


# 50471 27-Aug-1999 peter

$Id$ -> $FreeBSD$


# 46155 28-Apr-1999 phk

This Implements the mumbled about "Jail" feature.

This is a seriously beefed up chroot kind of thing. The process
is jailed along the same lines as a chroot does it, but with
additional tough restrictions imposed on what the superuser can do.

For all I know, it is safe to hand over the root bit inside a
prison to the customer living in that prison, this is what
it was developed for in fact: "real virtual servers".

Each prison has an ip number associated with it, which all IP
communications will be coerced to use and each prison has its own
hostname.

Needless to say, you need more RAM this way, but the advantage is
that each customer can run their own particular version of apache
and not stomp on the toes of their neighbors.

It generally does what one would expect, but setting up a jail
still takes a little knowledge.

A few notes:

I have no scripts for setting up a jail, don't ask me for them.

The IP number should be an alias on one of the interfaces.

mount a /proc in each jail, it will make ps more useable.

/proc/<pid>/status tells the hostname of the prison for
jailed processes.

Quotas are only sensible if you have a mountpoint per prison.

There are no privisions for stopping resource-hogging.

Some "#ifdef INET" and similar may be missing (send patches!)

If somebody wants to take it from here and develop it into
more of a "virtual machine" they should be most welcome!

Tools, comments, patches & documentation most welcome.

Have fun...

Sponsored by: http://www.rndassociates.com/
Run for almost a year by: http://www.servetheweb.com/


# 45366 06-Apr-1999 peter

Look at p_lock instead of P_NOSWAP etc as an indicator of unswappability.
(While here, put a #ifndef pgtok around the macro that gets a redefinition
warning)


# 41324 25-Nov-1998 dfr

Fix formatting of %CPU value on alpha.

Submitted by: Hidetoshi Shimokawa <simokawa@sat.t.u-tokyo.ac.jp>


# 39160 14-Sep-1998 dfr

Portability fixes when sizeof(int) != sizeof(long).


# 37246 28-Jun-1998 bde

Fixed printf format errors (second round with non-i386 typedefs).


# 37232 28-Jun-1998 bde

Oops, the previous log message should have read "Fixed type mismatches -
don't assume that time_t is long".


# 37231 28-Jun-1998 bde

Fixed printf format errors.


# 36497 31-May-1998 bde

Fixed imperfections in previous commit (a poor variable name,
excessive 64-bit arithmetic, and excessive changes).


# 36441 28-May-1998 phk

Some cleanups related to timecounters and weird ifdefs in <sys/time.h>.

Clean up (or if antipodic: down) some of the msgbuf stuff.

Use an inline function rather than a macro for timecounter delta.

Maintain process "on-cpu" time as 64 bits of microseconds to avoid
needless second rollover overhead.

Avoid calling microuptime the second time in mi_switch() if we do
not pass through _idle in cpu_switch()

This should reduce our context-switch overhead a bit, in particular
on pre-P5 and SMP systems.

WARNING: Programs which muck about with struct proc in userland
will have to be fixed.

Reviewed, but found imperfect by: bde


# 36352 25-May-1998 steve

If no value is present for the login name set it to '-'.
Also pretty-up the display of 'ps -Ortprio'.

PR: 4947
Submitted by: Martin Kammerhofer <dada@sbox.tu-graz.ac.at>


# 36049 15-May-1998 charnier

Correct use of .Nm. Add rcsid.


# 33010 02-Feb-1998 dyson

Display VSZ much more accurately now.


# 27857 03-Aug-1997 peter

Fix "lstart". (Displays "19" rather than time)

PR: 4206
Submitted by: Tetsuya Furukawa <tetsuya@secom-sis.co.jp>


# 27856 03-Aug-1997 peter

Kill #ifndef NEWVM etc. It affected a lot of other things besides
VM structure (eg: credentials etc) and it's highly unlikely we'll ever
get to see the "tainted" BSD<=4.3 VM code in public use. Although it
indicated the way some things used to be done, it obfuscates things too
much.


# 25271 29-Apr-1997 jkh

Dynamically adjust size of displayed username to the longest username which
appears, not the longest _maximum_ username (this should probably also go
into 2.2, for the day when we bump up the username length there too).

Submitted-By: Terry Lambert <terry@lambert.org>


# 24983 16-Apr-1997 jdp

When "-c" is specified, don't pad the command with spaces if it is
the last field on the line. "ps -axlc" was needlessly wrapping
around on 80-character windows.


# 22988 22-Feb-1997 peter

Revert $FreeBSD$ to $Id$


# 21673 14-Jan-1997 jkh

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 20420 14-Dec-1996 steve

-Wall cleaning.


# 19068 21-Oct-1996 peter

Implement a -c option to ps to display the short command name instead of
the full argument vector.

I've bumped into a few things that expected this switch to be present,
the most recent was the snmp package in ports. I'm not 100% sure of the
origins of this, but Linux has it, so does the "BSD-compatable" version
of ps on our SVR4 systems (so I assume SunOS has it too).


# 16835 29-Jun-1996 peter

Make %CPU add up closer to 100%.. At least, it now agrees with top.. :-)

Pointed out by: bde


# 16833 29-Jun-1996 peter

Fix (I think) the %MEM count in 'ps -u'. It was bogusly taking the
vm_rssize (in pages, not bytes), then dividing (bogusly) by the page size,
then using that as a fraction of the total pages.


# 15541 02-May-1996 phk

CLSIZE -> getpagesize()


# 15527 02-May-1996 phk

Replace NBPG with getpagesize()


# 11890 28-Oct-1995 phk

I add #include <sys/user.h>


# 11021 26-Sep-1995 peter

Correct the alignment of the tty column, which was affected by my change to
allow more than two tty characters.

David Greenman pointed out that when a process that had been revoked from
it's controlling tty, the "-" sign was detached from any two-character
names.


# 10553 03-Sep-1995 peter

Increase the tty column width from 2 to 3 characters.

This gives us more room to breath with tty names, especially with drivers
that support large numbers of ports.. eg: specialix and digiboard.

This does not actually change the current tty names, it just allows room
for reporting more characters if the drivers use them.


# 9987 07-Aug-1995 wollman

Delete bogus referneces to timezone code internal header file `tzfile.h',
which is no longer bogusly installed in /usr/include.


# 8855 29-May-1995 rgrimes

Remove trailing whitespace.

Reviewed by: phk


# 7165 19-Mar-1995 joerg

You will find enclosed some changes to make gcc -Wall more happy in
/usr/src/bin. Note that some patches are still needed in that directory.

I (Joerg) finished most of Philippe's cleanup. /bin/sh will still
need *allot* of work, however.

Submitted by: charnier@lirmm.fr (Philippe Charnier)


# 3301 02-Oct-1994 ache

Skip 'cua' 3 chars like 'tty' 3 chars


# 3296 02-Oct-1994 dg

On second thought...back out previous commit.


# 3295 02-Oct-1994 dg

Include rtprio.h


# 3044 24-Sep-1994 dg

Added $Id$


# 1557 26-May-1994 rgrimes

This commit was generated by cvs2svn to compensate for changes in r1556,
which included commits to RCS files with non-trunk default branches.


# 1556 26-May-1994 rgrimes

BSD 4.4 Lite bin Sources