Commit Graph

114 Commits

Author SHA1 Message Date
Martin Polednik
f8ccf3126e ps: recognize SCHED_DEADLINE 2016-11-07 10:23:01 +01:00
Thomas Petazzoni
4fc9a34802 ps/output.c: include <dlfcn.h> only when necessary
dlopen() functionality is only used when SELinux support is enabled, so
<dlfcn.h> only needs to be included when ENABLE_LIBSELINUX is
defined. This fixes the build in configurations where <dlfcn.h> is not
available.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2016-08-07 11:08:26 +02:00
Jim Warner
eca9168617 misc: adapted others to that new proc_t 'cgname' field
This patch adapts the ps program to a newly add proc_t
field and provides for new support in that top program
along with his man document (ps was already ok there).

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-07-06 21:33:17 +10:00
Jim Warner
8a198e3eaf ps: adapt to revised approach for --with-systemd build
We'll now display a '?' for any systemd field when our
library was built without that above configure option.

Since the man page documents such fields this approach
is far superior to that old (confusing) error message:
. error: unknown user-defined format specifier "slice"

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-06-07 20:49:30 +10:00
Shivkrishna A
3a52dfa340 Fix for Bug:1174313 2016-03-02 22:35:55 +05:30
Laurent Bigonville
5da390422d ps: use attr/current as fallback for context
If SELINUX is enabled but the machine is using another MAC system
(like apparmor), ps will fallback to just parsing
"/proc/%d/attr/current", otherwise the label/context would not
be properly displayed in that case.

References:
 https://bugs.debian.org/786956

Signed-off-by: Craig Small <csmall@enc.com.au>
2016-01-03 18:13:47 +11:00
Craig Small
0ee090ae16 ps: display control group name
The cgroup field while shown as a vector is a concatenated
string, so alot of the complexity of sorting and displaying
has gone.

This change simplifies the cgroup sorting and adds display
and sorting for the name attribute of the cgroup, if found.

Signed-off-by: Craig Small <csmall@enc.com.au>
2015-08-15 17:10:38 +10:00
Craig Small
4bd0e539af ps: sort by cgroup
A rather small fix to sort by cgroup. This sorting function
could be used for other string vector entries, but I can't
see why you want to for, say, environment.

Reference:
 https://bugs.debian.org/692279

Signed-off-by: Craig Small <csmall@enc.com.au>
2015-08-15 16:23:37 +10:00
Craig Small
313f936739 ps: enable sort by etimes
ps has two columns showing the same data which is elapsed time, just
the format is changed:
 etimes - elapsed time in seconds
 etime  - elapsed time in DD-hh:mm:ss

ps used to only sort by etime but not etimes, by making etimes
and alias of etime for sorting both flags work.

References:
 https://bugs.debian.org/794619

Signed-off-by: Craig Small <csmall@enc.com.au>
2015-08-06 22:08:13 +10:00
Jim Warner
caeebdc71f ps: exploit the simplified library interface for wchan
This patch was made necessary by those library changes
in support of recently revised/simplified wchan logic.

In addition, this commit eliminates a broken alternate
'namelist' provision which was intended to allow users
to specify a System.map file to be used in translating
addresses into function names. But, the real effect of
the now defunct 'N' and '-n' options was to indirectly
force addresses (not names) to be displayed since such
user named map files could not be successfully parsed.

Besides when the required FRAME_POINTER kconfig option
is absent there is no address to translate and when it
is present /proc/PID/wchan is already translated. Thus
an alternate mapping is unnecessary and inappropriate.

[ we'll forgive POSIX for documenting '-n  namelist' ]

Reference(s):
http://www.freelists.org/post/procps/WCHAN,11

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-06-19 19:09:20 +10:00
Jim Warner
f9e27afeb2 ps: add code to exploit the new library LXC containers
Reference(s):
https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1424253
https://bugs.launchpad.net/ubuntu/+source/procps/+bug/1424253

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-06-14 15:36:06 +10:00
Jim Warner
93d37cf57a ps: exploit library systemd support vs. internal logic
Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-17 13:31:06 +02:00
Lukas Nykryn
d66ed3350e ps: possibility to display slice unit for a process
Library systemd-login offers possibility to display
name of a systemd slice unit for specific pid.

This patch adds output option "slice" which will
show name of systemd slice unit.

To maintain compatibility with non-systemd systems,
procps must be configured with --with-systemd option
to enable this option.
2013-10-16 15:18:08 +02:00
Craig Small
dd6f24dbed Merge commit 'refs/merge-requests/13' of git://gitorious.org/procps/procps into merge-requests/13
Conflicts:
	pgrep.c
	ps/output.c
	ps/ps.1
2013-09-11 21:34:05 +10:00
Jim Warner
7c4894dd22 ps: address a potential 'newline' quirk the libselinux
Sometimes with libselinux present but SELinux inactive
the context reported is "unconfined" which contains an
embedded newline. This then causes misalignment of any
subsequent data. So, ps will now protect against that.

Reference(s):
http://www.freelists.org/post/procps/enablelibselinux-switch,14

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-08-09 17:58:52 +02:00
Jaromir Capik
5f663aee47 ps: making the libselinux support configurable
Previously the libselinux support was present
in the sources, but disabled with a preprocessor
condition (#if 0).
From now the libselinux support can be enabled with
the --enable-libselinux switch available
in the configuration script. That way is more
flexible than local patches modifying the condition
value from 0 to 1.
2013-08-07 17:52:38 +02:00
Václav Pavlín
39c6de4c87 ps: remove sd_ prefix from systemd output options
ps : This patch removes sd_ prefix from recently added systemd output options
to let them look more tied with the system.

Patch does not change behaviour of these options, only modifies their
representation to user.
2013-05-22 14:55:40 +02:00
Lukas Nykryn
7b50c2e918 ps: possibility to display seat for a process
Library systemd-login offers possibility to display
name of seat for a session on multi-seat systems.

This patch adds output option "sd_seat" which will
show name of seat or "-", when name of seat can not
be determined, but "seat0" should always exist.

To maintain compatibility with non-systemd systems,
procps must be configured with --with-systemd option
to enable this option.
2013-04-24 09:24:44 +02:00
Lukas Nykryn
38e8087d55 ps: possibility to display systemd user unit for a process
Library systemd-login offers possibility to display
name of systemd user unit for specific pid. Note that not all
processes are part of a user unit.

This patch adds output option "sd_uunit" which will
show name of user unit or "-", when process does not belong
to any user unit. This is similar to "sd_unit" but applies
to user units instead of system units.

To maintain compatibility with non-systemd systems,
procps must be configured with --with-systemd option
to enable this option.
2013-04-24 09:24:44 +02:00
Lukas Nykryn
4c1536d5f1 ps: possibility to display machine name for a process
Library systemd-login offers possibility to display
the name of the VM or container which process belongs to.

This patch adds output option "sd_machine" which will
show machine name or "-" when the name can not be determined.

To maintain compatibility with non-systemd systems,
procps must be configured with --with-systemd option
to enable this option.
2013-04-24 09:24:44 +02:00
Lukas Nykryn
785776c10d ps: possibility to display uid of session owner for a process
Library systemd-login offers possibility to display the Unix
user identifier of the owner of the session of a process.
This information will also be displayed for user processes which
are shared between multiple login sessions of the same user,
where sd_session will be blank.

This patch adds output option "sd_ouid" which will show
user UID or "-", when there is no owner for a process.

To maintain compatibility with non-systemd systems,
procps must be configured with --with-systemd option
to enable this option.
2013-04-24 09:24:44 +02:00
Lukas Nykryn
716d96b8eb ps: possibility to display login session for a process
Library systemd-login offers possibility to display name
of login session for specific pid.
Note that not all processes are part of a login session
(e.g. system service processes, user processes that are shared
between multiple sessions of the same user, or kernel threads).

This patch adds output option "sd_session" which will
show name of session or "-", when process does not belong
to any session.

To maintain compatibility with non-systemd systems,
procps must be configured with --with-systemd option
to enable this option.
2013-04-24 09:24:44 +02:00
Lukas Nykryn
7ab5d33c5c ps: possibility to display systemd unit for a process
Library systemd-login offers possibility to display
name of a systemd unit file for specific pid. Note that
not all processes are part of a system unit/service
(e.g. user processes, or kernel threads).

This patch adds output option "sd_unit" which will
show name of systemd unit or "-", when process does not
belong to any unit.

To maintain compatibility with non-systemd systems,
procps must be configured with --with-systemd option
to enable this option.
2013-04-24 09:24:44 +02:00
Aristeu Rozanski
a01ee3c0b3 procps: add support for linux namespaces
Each process in Linux has a /proc/<pid>/ns directory which contains
symbolic links to pipes that identify which namespaces that process
belongs to. This patch adds support for ps to display that information
optionally.

Signed-off-by: Aristeu Rozanski <arozansk@redhat.com>
2013-04-16 15:05:21 -04:00
Jaromir Capik
dfc671b4c3 Fixing negative ETIME field in ps (rhbz#871819, rhbz#433266) 2012-12-13 21:34:05 +11:00
Sami Kerola
4a6df5b133 ps: cut out code unused code
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-11-06 22:30:02 +11:00
Jim Warner
a65de0fd73 ps: favor truncation of long names over POSIX/UNIX standard
The UNIX and POSIX standards require that user and
group names be printed as decimal integers when there
is insufficient room.  This has led to a constant
stream of bug reports.

With this commit, long names will be truncated and
displayed with a trailing visual clue.

To avoid truncation. the UNIX and POSIX way to change
column width is to rename the column:
   ps -o pid,user=CumbersomeUserNames -o comm

The easy way is to directly specify the desired width:
   ps -o pid,user:19,comm

Reference:
http://www.freelists.org/post/procps/rhbz737215-ps-does-not-resolve-some-user-names

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-09-27 22:16:53 +10:00
Jim Warner
ede5d99f6c ps: exploit library changes to cgroup & supgid
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-08-29 17:26:43 +10:00
Jim Warner
f4b6de1136 ps: restore missing space when environment is displayed
This commit restores the missing space between command
lines and the environment when the later is being
displayed.  Below is a brief history of that elusive
character.

commit bb4f08ba29
Date:   Thu Aug 11 07:42:14 2011 +1000
   The ps program was altered for improved args/comm
   compliance.  At this time, the needed space was
   present due to a buglet in the new library
   read_unvectored function used by fill_cmdline_cvt.

commit a5881b5a4e
Date:   Thu Dec 8 10:19:38 2011 -0600
   The trailing space was eliminated so that the
   file2strvec and fill_cmdline_cvt returned
   command lines contained no trailing space.

   However, this created a buglet when control group
   hierarchies were displayed and the final cgroup
   was empty.

   This is also where the undetected ps buglet was
   created.

commit c3a1239efe
Date:   Sun Dec 11 12:00:50 2011 -0600
   The control group anomaly was fixed but the impact
   on ps args/environ was still not detected.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-08-29 17:24:54 +10:00
Jim Warner
421b08a4df all: fix misspellings in docs and program comments
We might as well join the coreutils and util-linux
projects in correcting our own typos.

The following was left unchanged:
   top/top.c[1797]: thru -> "through"

references:
http://lists.gnu.org/archive/html/coreutils/2012-04/msg00057.html
http://marc.info/?l=util-linux-ng&m=133518057419736&w=2

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-04-25 13:46:02 +10:00
Sami Kerola
ce61089059 docs: clarification to license headers in files
Add license header to all files.  The summary of licensing is below,
taken from Craig Small's email which is referred in commit message
tail.

sysctl and pgrep are GPL 2+
The rest is LGPL 2.1+

Reference: http://www.freelists.org/post/procps/Incorrect-FSF-address-in-the-license-files,8
Bug-Redhat: https://bugzilla.redhat.com/show_bug.cgi?id=797962
CC: Craig Small <csmall@enc.com.au>
CC: Jaromir Capik <jcapik@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-03 18:41:11 +11:00
Sami Kerola
60ea600599 ps: fix compiler warnings
common.h:23:19: warning: ISO C does not permit named variadic macros [-Wvariadic-macros]
global.c:499:3: warning: ISO C does not support the '%Ld' gnu_printf format [-Wformat]
output.c:134:1: warning: 'sr_cstime' defined but not used [-Wunused-function]
output.c:816:3: warning: ISO C does not support the '%Lu' gnu_printf format [-Wformat]
output.c:816:3: warning: ISO C does not support the '%Lu' gnu_printf format [-Wformat]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-03 18:36:29 +11:00
Craig Small
502a79e02f Merge remote-tracking branch 'sami/to-craig' into sami-merge
Conflicts:
	pgrep.c
	w.c
2012-03-03 13:56:32 +11:00
Sami Kerola
79ceb30b5c ps: unify cases and remove trailing dots in messages
Strings with lower caps & no trailing dots have greater change to
have multiple occurences, meaning less effort for translators, than
strings with them.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-01-15 20:52:58 +01:00
Mike Fleetwood
2bac5334b0 ps: display the nice value for processes with the SCHED_BATCH scheduler policy
Ps command does not display the nice value for processes with the SCHED_BATCH
scheduler policy, only for SCHED_OTHER.

Boinc (http://boinc.berkeley.edu/) client runs project processing jobs on
Linux using SCHED_BATCH scheduler policy and nice value 19.  The nice value
is not displayable by ps.

Steps to Reproduce:
1. Run process using SCHED_BATCH scheduler policy with nice value.
    ./test-schedbatch 18 &
2. Display process details:
    ps -o pid,ppid,user,comm,cls,nice

Results before:
[mike@rockover c]$ ps -o pid,ppid,user,comm,cls,nice
  PID  PPID USER     COMMAND         CLS  NI
18205  2540 mike     bash             TS   0
20552 18205 mike     test-schedbatch   B   -
20553 18205 mike     ps               TS   0
[mike@rockover c]$ awk '{printf "%5d %-17s %1d %2d\n", $1, $2, $41, $19}'
/proc/20552/stat
20552 (test-schedbatch) 3 18

Results after this patch:
[mike@rockover c]$ ps -o pid,ppid,user,comm,cls,nice
  PID  PPID USER     COMMAND         CLS  NI
18205  2540 mike     bash             TS   0
20552 18205 mike     test-schedbatch   B  18
20553 18205 mike     ps               TS   0

Additional info: Here is the fragment from the sched_setscheduler(2) manual
page on the subject:

   SCHED_BATCH: Scheduling batch processes
       (Since  Linux 2.6.16.)  SCHED_BATCH can only be used at static
       priority 0.  This policy is similar to SCHED_OTHER in that it
       schedules the process according to its dynamic priority (based on the
       nice value).  The difference is that this policy will cause the
       scheduler to always assume that the process is CPU-intensive.
       Consequently, the scheduler will apply a small scheduling penalty with
       respect to wakeup behaviour, so that this process is mildly disfavored
       in scheduling decisions.

       This policy is useful for workloads that are noninteractive, but do
       not want to lower their nice value, and for workloads that want a
       determin- istic scheduling policy without interactivity causing extra
       preemptions (between the workload's tasks).

Reference: https://bugzilla.redhat.com/show_bug.cgi?id=741090
Acked-by: Jaromir Capik <jcapik@redhat.com>
Acked-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Mike Fleetwood <mike.fleetwood@googlemail.com>
2012-01-09 21:37:41 +01:00
Jim Warner
71b72b36ce ps: minor reformatting and trailing whitespace elimination
This patch mostly reorganizes include files and eliminates
some useless trailing whitespace.

It also adopts the standard procps-ng unconditional approach
to nls initialization.
2012-01-04 08:58:53 +11:00
Sami Kerola
c1fa3bfce8 misc: compiler warning fixes
Fix few compiler warnings. Some of these warnings appeared multiple
times, and the listing bellow is more about which sort of errors
where fixed.

devname.c:87:12: warning: comparison of integers of different signs: 'int' and 'unsigned long'
output.c:389:36: warning: passing 'char **const' to parameter of type 'const char *const restrict *' discards qualifiers in nested pointer types
output.c:611:31: warning: comparison of integers of different signs: 'const unsigned long' and 'int'
stacktrace.c:33:37: warning: unused parameter 'signum'

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:30:50 +01:00
Sami Kerola
4bd36d1483 ps: add gettext support
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:30:45 +01:00
Craig Small
0c82b0ceda ps: rename SZ to SIZE
Means we do not follow SCO but less confusion.

A patch from Debian.

Bug-Debian: http://bugs.debian.org/541061
Backported-by: Sami Kerola <kerolasa@iki.fi>
2011-12-18 22:50:12 +11:00
Jessica McKellar
9ecd3c8414 ps: add sorting to %mem for ps
A patch from Debian.

Bug-Debian: http://bugs.debian.org/599043
Backported-by: Sami Kerola <kerolasa@iki.fi>
2011-12-18 22:48:38 +11:00
Alfredo Esteban
daf4014205 ps: --sort does not work with time argument
A patch from Debian.

Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=508435
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=508435
Backported-by: Sami Kerola <kerolasa@iki.fi>
2011-12-18 22:29:12 +11:00
Craig Small
e4c45d6984 added ps etimes, miscellaneous top enhancements
ps program
 . etimes added for ELAPSED expressed in seconds
 . time_t used in place of former unsigned long

top program
 . corrected scroll message bug when 'x' toggle on
 . fixed forest view potential missing libflags bug
 . improved 'k' default signal invocation logic
 . enhanced logic for %CPU maximums displayed
 . made signal handling more robust and efficient
2011-09-12 22:18:23 +10:00
Craig Small
0e6ac0db3e added tgid support plus miscellaneous cleanup
ps
   . added tgid support
   . made process/task naming consistent
 top
   . added tgid support
   . standardized pid related width logic
 documents
   . added tgid to ps & top man documents
 library
   . fixed OOMEM_ENABLE readtask bug
   . corrected header typo for tgid
2011-08-17 21:01:35 +10:00
Craig Small
bb4f08ba29 refined library i/f and improved performance
Library changes
   readproc
    . added readeither to more efficiently
      fill both process and thread proc_t
    . added readproctab3, uses readeither
    . included task path support in:
        fill_cgroup_cvt, fill_cmdline_cvt,
        read_unvectored
    . QUICK_THREADS #define allows copying
      process info vs. repeatedly reading
    . simple_nexttid no longer values ppid
    . path var made non-static in readtask
    . documented 'proc_data_t' in .h file
    . tweaked some c comments & formatting
   library.map
    . added new readeither, readproctab3
 Program changes
   ps
    . exploits readproctab3 where possible
    . improved args/comm compliance
   top
    . exploits readeither
2011-08-11 07:42:14 +10:00
Craig Small
3ef4823f90 supgid/supgrp support, improved library interface
Library changes
   readproc
    . added support for supplementary groups
    . eliminated 2 potential mem leak sources
       . shortcut used for multi-threaded str
         vectors & ptrs was obsoleted
       . freeing of proc_t related dynamic
         memory now rests with the library
    . standardized/normalized many c comments
   sysinfo
    . corrected note regarding glibc & cpuinfo
   library.map
    . made the visible freeproc accessable
 Program changes
   pmap
    . initialized buffer for new readproc i/f
    . eliminated now obsolete free() call
   ps
    . added width aware supgrp support
    . initialized buffers for new readproc i/f
    . eliminated now obsolete free() calls
   top
    . added supgrp support as variable width
    . eliminated now obsolete free() calls
    . expoilted library freeproc function
    . corrected -h|v args text & spacing
    . updated some c comments
 Documentation changes
   ps.1
    . added supgid and supgrp
   top.1
    . added supgid and supgrp
    . addition of above required renumbering
      many fields in section 3a. DESCRIPTIONS
2011-08-01 21:28:46 +10:00
Jim Warner
7b0fc19e9d enhanced libproc cgroup/cmdline support, exploited by top
Library Changes
. added PROC_EDITCMDLCVT flag
. added an internal (static) fill_cmdline_cvt function:
  - reads and "escapes" /proc/#/cmdline
  - returns result as a single string in a single vector
  - callers are guaranteed a cmdline (no more NULL)
. added vectorize_this_str function, exploited by
  fill_cgroup_cvt, fill_cmdline_cvt
. generalized read_cmdline function as read_unvectored, now
  exploited by fill_cgroup_cvt, fill_cmdline_cvt, read_cmdline
  ( cgroup and cmdline no longer need be converted to string )
  ( vectors before being transformed to final representation )
. fixed bug regarding skipped group numbers (when enabled)
. escape_str made responsible for all single byte translation
  with distinction between control chars + other unprintable
. added escaped_copy function for already escaped strings
. reorganized parts of proc_t to restore formatting standards
  ( displacement changes shouldn't matter with new version # )
. former ZAP_SUSEONLY #define now OOMEM_ENABLE
. added to library.map: escaped_copy; read_cmdline

Top Program Changes
. exploited the new PROC_EDITCMDLCVT provision
. eliminated now obsolete #include "proc/escape.h"
. changed the P_WCH display format if no kernel symbol table
. fixed very old bug in lflgs for out-of-view sort fields
. former ZAP_SUSEONLY #define now OOMEM_ENABLE

Ps Program Changes
. exploited the new PROC_EDITCMDLCVT provision
. exploited the new escaped_copy function
. consolidated pr_args and pr_comm into pr_argcom

Signed-off-by: Jan Görig <jgorig@redhat.com>
2011-05-18 10:33:44 +02:00
Jan Görig
8621387c77 Updated ps to use new cgroup interface 2011-05-05 12:20:30 +02:00
Jan Görig
e47f54c569 Merged changes from procps-3.2.8 not present in CVS 2011-02-10 13:40:29 +01:00
Jan Görig
59679bc2a2 Rewritten cgroup support and suppressed root cgroup
Bug-Redhat: https://bugzilla.redhat.com/show_bug.cgi?id=593267
Signed-off-by: Jan Görig <jgorig@redhat.com>
2011-02-10 13:40:29 +01:00
Jan Görig
4d3c19af52 Read the system boot time from /proc instead of computing
Read the time of system boot from /proc/stat (entry: btime) instead
of computing it as the difference between the current time and the
uptime. This is the only way to get a consistent result which won't
possibly change from one run to the next.

The problems with the original code were:
* Both the current time and the uptime are rounded down to the second,
  but the system doesn't boot on an integer second value so they do not
  tick at the same moment. Thus, the rounding errors can cause a one
  second difference from one run to the next.
* We can't read the uptime and the current time at the exact same moment
  anyway, so the time difference we compute is bound to be inaccurate.
Bug-Redhat: https://bugzilla.redhat.com/show_bug.cgi?id=222251
Author: Jean Delvare <jdelvare@suse.de>
Reviewed-by: Craig Small <csmall@debian.org>
2010-12-16 10:30:39 +01:00