aboutsummaryrefslogtreecommitdiff
path: root/bin/ps/ps.c
Commit message (Collapse)AuthorAgeFilesLines
* ps(1): Fix formatting of the "command" field for kernel threads.Mark Johnston2020-07-281-4/+7
| | | | | | | | | | | | | | | | | | When -H is specified, for kernel threads the command is formatted as "<proc name>/<td name>" and truncated to MAXCOMLEN. But each of the proc name and td name may be up to MAXCOMLEN bytes in length. Also handle the ki_moretdname field to ensure that the full thread name gets printed. This is already handled correctly when formatting for "-o tdname". Reported by: freqlabs Reviewed by: freqlabs MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D25840 Notes: svn path=/head/; revision=363649
* ps(1): don't try to handle non-SMP systemsPiotr Pawel Stefaniak2020-06-271-15/+0
| | | | | | | | | | As reported by kib, sysctl machdep.smp_active doesn't exist and on UP we return CPU 0 for all threads anyway. Reported by: kib Notes: svn path=/head/; revision=362707
* ps(1): reuse keyword "cpu" to show CPU numberPiotr Pawel Stefaniak2020-06-271-0/+15
| | | | | | | | | | | | | | | | | | | | | | | This flag will now show the processor number on which a process is running. This change was inspired by PR129965. Initially I didn't think that the patch attached to it was correct -- it sacrificed ki_estcpu use in "cpu" for ki_lastcpu and I thought that the old functionality should be kept and the new (cpu#) one added to it. But I've since discovered that ki_estcpu is sched_4bsd-specific. What's worse, it represents the same thing as ki_pctcpu, except ki_pctcpu is universal -- so "%cpu" has been using it successfully. Therefore, I've decided to replace information based on ki_estcpu with information based on ki_oncpu/ki_lastcpu. Key parts of the code and manual changes were borrowed from top(1). PR: 129965 Reported by: Nikola Knežević MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D25377 Notes: svn path=/head/; revision=362705
* ps: remove xo_no_setlocale() callYuri Pankov2020-06-091-1/+0
| | | | | | | | | | Apparently libxo was fixed to do the right thing on FreeBSD, and calling xo_no_setlocale() is no longer needed. Reported by: phil Notes: svn path=/head/; revision=361962
* ps: use %hs instead of %s format specifiersYuri Pankov2020-06-071-1/+2
| | | | | | | | | | | | | Use %hs (locale-based encoding) instead of %s (UTF-8) format for strings that are expected to be in current locale encoding (date/time, process names/argument list). PR: 241491 Reviewed by: phil Differential Revision: https://reviews.freebsd.org/D22160 Notes: svn path=/head/; revision=361887
* ps: extend the non-standard option -d (tree view) to work with -pPiotr Pawel Stefaniak2020-05-071-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Initially it seemed that there were multiple possible ways to do it. Processing option -p could conditionally add selected processes and their descendants to the list for further work, but it is not guaranteed to know whether the -d option has been used or not, and it also doesn't have access to the process list just yet. There is also descendant_sort() which has access to all possibly needed information, but serves the purely post-processing purpose of sorting output. Then there is the loop that uses invocation information and full process list to create a list of processes for final display. It seems the most natural place to implement this, but indeterminate state of the process list and volatility of the final list that is being created obstruct adding an elegant search for all elements of process descendancy trees. So I opted for adding another loop, just before the one I mentioned above. For all selected processes it conditionally adds direct descendants to the end of this list of selected processes. Possible usage: * ps -auxd -p $$ * ps -auxd -p 1 * while x=$(pgrep svnlite); do clear; ps auxd -p $x; sleep 2; done * ps -auxd -p `pgrep make` Reviewed by: kevans, kaktus (earlier version) MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D24380 Notes: svn path=/head/; revision=360786
* ps(1): fix some nitsEitan Adler2018-06-131-2/+2
| | | | | | | | | - fracmem and mempages are double. ki_rssize should be too - remove default case that is fully covered by all existing cases - mark usage as dead Notes: svn path=/head/; revision=335023
* Change ps(1) output width to unlimited if not interactiveMike Karels2018-03-101-1/+6
| | | | | | | | | | | | | | | | | | Apply patch submitted with PR 217159 to make ps use unlimited width when not associated with a terminal (i.e., none of stdout, stdin, or stderr is a tty). Update comments and man page correspondingly. This change was requested to work around lack of -ww in scripts from third-party packages, including Hadoop, and adds a small measure of Linux compatibility. Hopefully few if any non-interactive scripts depend on the old default of 79. PR: 217159 Submitted by: n.deepak at gmail.com Reviewed by: vangyzen jhb Differential Revision: https://reviews.freebsd.org/D14614 Notes: svn path=/head/; revision=330712
* Revert r314685 in psMike Karels2018-02-281-2/+9
| | | | | | | | | | | Revert r314685, and add a comment describing the original behavior and the intent. Reviewed by: dab@ vangyzen@ jhb@ Differential Revision: https://reviews.freebsd.org/D14530 Notes: svn path=/head/; revision=330091
* General further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-0/+2
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326025
* Fix kvm_getprocs(3) error reporting in ps(1).Edward Tomasz Napierala2017-10-061-1/+5
| | | | | | | | | | | | | | | Previously it just didn't work at all - kvm_getprocs(3) doesn't update the &nentries when it returns NULL. The end result was that ps(1) showed garbage data instead of reporting kinfo_proc size mismatch. Reviewed by: cem Obtained from: CheriBSD MFC after: 2 weeks Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D12414 Notes: svn path=/head/; revision=324367
* ps(1): Fix -w + UNLIMITED handlingConrad Meyer2017-03-071-1/+1
| | | | | | | | | | | | | | | | | | | | | A follow-up fix for r314685. Because the -w flag is parsed after ps(1) infers termwidth from COLUMNS and stdout, and UNLIMITED happens to be the zero value, the single -w flag in combination with a non-terminal stdout or COLUMNS=0 could result in output truncated at 131 characters. (Despite the output being unlimited without -w.) Obviously, adding more -w shouldn't truncate output lines. The committed patch is from bdrewery@, and I've reviewed and tested it. Submitted by: bdrewery@ Reported by: bdrewery@ Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=314832
* ps(1): Only detect terminal width if stdout is a ttyConrad Meyer2017-03-041-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If stdout isn't a tty, use unlimited width output rather than truncating to 79 characters. This is helpful for shell scripts or e.g., 'ps | grep foo'. This hardcoded width has some history: In The Beginning of History[0], the width of ps was hardcoded as 80 bytes. In 1985, Bloom@ added detection using TIOCGWINSZ on stdin.[1] In 1986, Kirk merged a change to check stdout's window size instead. In 1990, the fallback checks to stderr and stdin's TIOCGWINSZ were added by Marc@, with the commit message "new version."[2] OS X Darwin has a very similar modification to ps(1), which simply sets UNLIMITED for all non-tty outputs.[3] I've chosen to respect COLUMNS instead of behaving identically to Darwin here, but I don't feel strongly about that. We could match OS X for parity if that is desired. [0]: https://svnweb.freebsd.org/csrg/bin/ps/ps.c?annotate=1065 [1]: https://svnweb.freebsd.org/csrg/bin/ps/ps.c?r1=18105&r2=18106 [2]: https://svnweb.freebsd.org/csrg/bin/ps/ps.c?r1=40675&r2=40674&pathrev=40675 [3]: https://opensource.apple.com/source/adv_cmds/adv_cmds-168/ps/ps.c.auto.html PR: 217159 Reported by: Deepak Nagaraj <n.deepak at gmail.com> Notes: svn path=/head/; revision=314685
* Renumber copyright clause 4Warner Losh2017-02-281-1/+1
| | | | | | | | | | | | Renumber cluase 4 to 3, per what everybody else did when BSD granted them permission to remove clause 3. My insistance on keeping the same numbering for legal reasons is too pedantic, so give up on that point. Submitted by: Jan Schaumann <jschauma@stevens.edu> Pull Request: https://github.com/freebsd/freebsd/pull/96 Notes: svn path=/head/; revision=314436
* Addm missed required call to xo_finish() when only header is printed.Konstantin Belousov2016-07-231-0/+1
| | | | | | | | | Reported by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=303213
* Fix CID 1011370 (Resource leak) in ps.Don Lewis2016-05-251-6/+9
| | | | | | | | | | | | | | | | There is no need to to call strdup() on the value returned by fmt(). The latter calls fmt_argv() which always returns a dynamically allocated string, and calling strdup() on that leaks the memory allocated by fmt_argv(). Wave some const magic on ki_args and ki_env to make the direct assignment happy. This requires a tweak to the asprintf() case to avoid a const vs. non-const mismatch. Reported by: Coverity CID: 1011370 MFC after: 1 week Notes: svn path=/head/; revision=300648
* Use NULL instead of 0 for pointers.Marcelo Araujo2016-04-191-1/+1
| | | | | | | | | kvm_open(3) will return NULL when it cannot access kernel virtual memory. MFC after: 2 weeks. Notes: svn path=/head/; revision=298233
* Remove unused variable, this variable fmtstr was introduced at revision r225868Marcelo Araujo2015-06-011-6/+1
| | | | | | | | | | and it is not used anymore after the convertion to use libxo at revision r283304. Differential Revision: D2678 Reviewed by: marcel Notes: svn path=/head/; revision=283867
* Convert to use libxo. Document use of libxo as well.Marcel Moolenaar2015-05-221-39/+62
| | | | | | | | Obtained from: Phil Shafer <phil@juniper.net> Sponsored by: Juniper Networks, Inc. Notes: svn path=/head/; revision=283304
* Prevent access to an uninitialized variablePedro F. Giffuni2015-01-311-1/+1
| | | | | | | | | | The "-h" option may access an uninitialized value. Prevent it by properly initializing the value. CID: 1006559 Notes: svn path=/head/; revision=277979
* Add -J to filter by matching jail IDs and names.Bryan Drewery2014-05-021-3/+43
| | | | | | | | | | | | | -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 Notes: svn path=/head/; revision=265229
* - Move 'showthreads' check out of fmt.c.John Baldwin2013-01-191-1/+1
| | | | | | | | - Update shadow copy of fmt_argv() prototype in w.c and fix calls for additional parameter. Notes: svn path=/head/; revision=245635
* Include the thread name along with the command name when displaying theJohn Baldwin2013-01-181-5/+6
| | | | | | | | | | | | 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 Notes: svn path=/head/; revision=245610
* Use kern.max_pid sysctl to obtain maximum PID number instead of using localPawel Jakub Dawidek2012-12-121-3/+17
| | | | | | | | | define. Reviewed by: jhb Notes: svn path=/head/; revision=244154
* Avoid passing uninitialized stack to addelem() if called with an empty arg.Ed Maste2012-08-291-2/+2
| | | | | | | PR: bin/171174 Notes: svn path=/head/; revision=239883
* Spelling fixes for bin/Ulrich Spörlein2012-01-071-1/+1
| | | | Notes: svn path=/head/; revision=229782
* No need in procfs(5).Mikolaj Golub2011-11-221-21/+0
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=227840
* Make ps(1) automatically size its column widths.Edward Tomasz Napierala2011-09-291-30/+73
| | | | Notes: svn path=/head/; revision=225868
* Fix some typos under bin/Ulrich Spörlein2011-05-221-1/+1
| | | | | | | Found by: codespell Notes: svn path=/head/; revision=222178
* Get rid of DSIZ; instead just call the sizing function if provided.Edward Tomasz Napierala2011-04-121-3/+3
| | | | Notes: svn path=/head/; revision=220574
* Initialize the execfile argument to NULL instead of _PATH_DEVNULL. This ↵Rebecca Cran2010-02-081-1/+2
| | | | | | | | | | | allows the -M option to be used without specifying -N. PR: bin/138146 Approved by: rrs (mentor) MFC after: 3 days Notes: svn path=/head/; revision=203688
* Add the -d switch to the usage message.Brian Somers2009-07-231-1/+1
| | | | | | | | | Submitted by: Emil Mikulic - emil at dmr dot ath dot cx Approved by: re (kib) MFC after: 1 week Notes: svn path=/head/; revision=195830
* Remove redundant whitespaceBrian Somers2009-05-181-3/+2
| | | | Notes: svn path=/head/; revision=192280
* Add a -d option to ps to display descendant info with the output.Brian Somers2009-05-171-3/+129
| | | | | | | | | This is similar to linux's -H (or -f) switch. MFC after: 3 weeks Notes: svn path=/head/; revision=192239
* Remove unnessasary castKevin Lo2008-07-181-1/+1
| | | | Notes: svn path=/head/; revision=180596
* Teach ps(1) to parse pts TT values (i.e. '0', '1') for the -t flag.John Baldwin2007-11-081-9/+23
| | | | | | | | MFC after: 1 week Reported by: kris Notes: svn path=/head/; revision=173492
* Introduce a way to make pure kernal threads.Julian Elischer2007-10-261-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=173004
* - Move all of the PS_ flags into either p_flag or td_flags.Jeff Roberson2007-09-171-2/+2
| | | | | | | | | | | | | | | | | - 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) Notes: svn path=/head/; revision=172207
* Sync program's usage() with manpage's SYNOPSIS.Ruslan Ermilov2005-02-091-3/+3
| | | | Notes: svn path=/head/; revision=141578
* Use statfs instead of getmntinfo(). This will make the procfs checksChristian S.J. Peron2004-11-191-9/+6
| | | | | | | | | | play nicer in prisons. It also simplifies things. Reviewed by: rwatson Bumped into by: Jilles Tjoelker Notes: svn path=/head/; revision=137890
* Currently if the user specifies -e and procfs is not mounted on /proc,Christian S.J. Peron2004-11-141-0/+25
| | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=137696
* Removed bitrot.Ruslan Ermilov2004-11-131-12/+2
| | | | Notes: svn path=/head/; revision=137670
* Improve checking for `ps -t <dev>', and give better error messages whenGarance A Drosehn2004-06-271-8/+16
| | | | | | | | 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). Notes: svn path=/head/; revision=131209
* Fix a bug I introduced by some last-minute changes in -r 1.102. I endedGarance A Drosehn2004-06-241-1/+1
| | | | | | | | | up checking the wrong variable for NULL. Submitted by: bde Notes: svn path=/head/; revision=131024
* Rework the logic for `-t <tty>', such that it accepts "ttyp0" and "console",Garance A Drosehn2004-06-241-15/+43
| | | | | | | in addition to "/dev/ttyp0" or "p0" and "/dev/console" or "co". Notes: svn path=/head/; revision=131010
* Change "struct varent" to use the standard queue(8) macros, instead ofGarance A Drosehn2004-06-231-7/+7
| | | | | | | | | using it's own version of the same basic algorithm. Submitted by: part by Cyrille Lefevre, part of it done by me Notes: svn path=/head/; revision=130999
* Add a check for defunct processes in saveuser(), so the output for "args"Garance A Drosehn2004-06-231-10/+18
| | | | | | | | | | (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 Notes: svn path=/head/; revision=130991
* Include the `-c' option in the usage() message.Garance A Drosehn2004-06-231-1/+1
| | | | | | | Submitted by: Cyrille Lefevre Notes: svn path=/head/; revision=130973
* In the sorting routine, sort by thread-id if two processes have the same PID.Garance A Drosehn2004-06-231-0/+2
| | | | | | | Submitted by: Cyrille Lefevre Notes: svn path=/head/; revision=130972
* Have the main() routine calculate %CPU and (if needed) memory informationGarance A Drosehn2004-06-201-36/+29
| | | | | | | | | | 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. Notes: svn path=/head/; revision=130816