]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
prlimit: support 'PID:inode' process address format
authorChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Sun, 29 Mar 2026 18:55:17 +0000 (14:55 -0400)
committerChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Mon, 30 Mar 2026 12:44:10 +0000 (08:44 -0400)
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
sys-utils/prlimit.1.adoc
sys-utils/prlimit.c

index fbfbc9f0ad576b4235796b06d0fa8360f134bbfd..c4808936d7a8b7b85ba208f771037438db483d51 100644 (file)
@@ -20,7 +20,7 @@ prlimit - get and set process resource limits
 
 == SYNOPSIS
 
-*prlimit* [options] [**--**_resource_[**=**_limits_]] [*--pid* _PID_]
+*prlimit* [options] [**--**_resource_[**=**_limits_]] [*--pid* _PID_[:_inode_]]
 
 *prlimit* [options] [**--**_resource_[**=**_limits_]] _command_ [_argument_...]
 
@@ -48,9 +48,9 @@ Do not print a header line.
 *-o*, *--output* _list_::
 Define the output columns to use. If no output arrangement is specified, then a default set is used. Use *--help* to get a list of all supported columns.
 
-*-p*, *--pid* _PID_::
-Specify the process ID.  Without this option (and without a _command_),
-the running process will be used.
+*-p*, *--pid* _PID_[:_inode_]::
+Specify the process ID. Without this option (and without a _command_), the running process will be used.
+The _inode_ uniquely identifies the process identity in the pidfs. To retrieve a process's inode number you can use the *getino*(1) utility.
 
 *--raw*::
 Use the raw output format.
@@ -138,7 +138,8 @@ mailto:dave@gnu.org[Davidlohr Bueso] - In memory of Dennis M. Ritchie.
 == SEE ALSO
 
 *ulimit*(1p),
-*prlimit*(2)
+*prlimit*(2),
+*getino*(1)
 
 include::man-common/bugreports.adoc[]
 
index 72390bb3d5561234c068fa0c70ed086049209aa9..8d118a8f5d030d704a370917672bc1dd356f2f87 100644 (file)
@@ -32,6 +32,8 @@
 #include "closestream.h"
 #include "path.h"
 #include "pathnames.h"
+#include "pidutils.h"
+#include "pidfd-utils.h"
 
 #ifndef RLIMIT_RTTIME
 # define RLIMIT_RTTIME 15
@@ -156,11 +158,18 @@ static void __attribute__((__noreturn__)) usage(void)
 {
        FILE *out = stdout;
        size_t i;
+       char *pid_arg = NULL;
+
+#ifdef USE_PIDFD_INO_SUPPORT
+       pid_arg = "PID[:inode]";
+#else
+       pid_arg = "PID";
+#endif
 
        fputs(USAGE_HEADER, out);
 
        fprintf(out,
-               _(" %s [options] [--<resource>=<limit>] [-p PID]\n"), program_invocation_short_name);
+               _(" %s [options] [--<resource>=<limit>] [-p %s]\n"), program_invocation_short_name, pid_arg);
        fprintf(out,
                _(" %s [options] [--<resource>=<limit>] COMMAND\n"), program_invocation_short_name);
 
@@ -505,9 +514,21 @@ static int add_prlim(char *ops, struct list_head *lims, size_t id)
        return 0;
 }
 
+static int parse_pid_str(char *pidstr, pid_t *pidnum)
+{
+       int pfd = -1;
+       uint64_t pidfd_ino = 0;
+
+       ul_parse_pid_str_or_err(pidstr, pidnum, &pidfd_ino);
+       if (pidfd_ino)
+               pfd = ul_get_valid_pidfd_or_err(*pidnum, pidfd_ino);
+
+       return pfd;
+}
+
 int main(int argc, char **argv)
 {
-       int opt;
+       int opt, pid_fd = -1;
        struct list_head lims;
 
        enum {
@@ -612,7 +633,8 @@ int main(int argc, char **argv)
                case 'p':
                        if (pid)
                                errx(EXIT_FAILURE, _("option --pid may be specified only once"));
-                       pid = strtopid_or_err(optarg, _("invalid PID argument"));
+
+                       pid_fd = parse_pid_str(optarg, &pid);
                        break;
                case 'o':
                        ncolumns = string_to_idarray(optarg,
@@ -671,5 +693,7 @@ int main(int argc, char **argv)
                errexec(argv[optind]);
        }
 
+       if (pid_fd >= 0)
+               close(pid_fd);
        return EXIT_SUCCESS;
 }