[PATCH] Let ionice -p handle multiple pids | |
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] | |
Makes ionice usable like renice, ie. ionice -p `pidof proc1 proc2 ...`
Signed-off-by: Stephan Maka <stephan@xxxxxxxxxxxxx>
---
schedutils/ionice.1 | 8 ++--
schedutils/ionice.c | 86 +++++++++++++++++++++++++++++++++++---------------
2 files changed, 64 insertions(+), 30 deletions(-)
diff --git a/schedutils/ionice.1 b/schedutils/ionice.1
index a17dd4f..d087164 100644
--- a/schedutils/ionice.1
+++ b/schedutils/ionice.1
@@ -47,7 +47,7 @@ accepts an argument. For real time and best-effort, \fI0-7\fR is valid
data.
.TP 7
\fB-p\fP
-Pass in a process pid to change an already running process. If this argument
+Pass in process PIDs to view or change already running processes. If this argument
is not given, \fBionice\fP will run the listed program with the given
parameters.
.TP 7
@@ -59,7 +59,7 @@ can happen due to insufficient privilegies or old kernel version.
.SH EXAMPLES
.LP
.TP 7
-# \fBionice\fP -c3 -p89
+# \fBionice\fP -c3 -p 89
.TP 7
Sets process with PID 89 as an idle io process.
.TP 7
@@ -67,9 +67,9 @@ Sets process with PID 89 as an idle io process.
.TP 7
Runs 'bash' as a best-effort program with highest priority.
.TP 7
-# \fBionice\fP -p89
+# \fBionice\fP -p 89 90
.TP 7
-Returns the class and priority of the process with PID 89.
+Returns the class and priority of the processes with PIDs 89 and 90.
.SH NOTES
Linux supports io scheduling priorities and classes since 2.6.13 with the CFQ
diff --git a/schedutils/ionice.c b/schedutils/ionice.c
index f5c02db..e3e5556 100644
--- a/schedutils/ionice.c
+++ b/schedutils/ionice.c
@@ -55,12 +55,31 @@ static void usage(void)
printf("\nJens Axboe <axboe@xxxxxxx> (C) 2005\n");
}
+void ioprio_print(int pid)
+{
+ int ioprio = 4, ioprio_class = IOPRIO_CLASS_BE;
+ ioprio = ioprio_get(IOPRIO_WHO_PROCESS, pid);
+
+ if (ioprio == -1) {
+ perror("ioprio_get");
+ exit(EXIT_FAILURE);
+ } else {
+ ioprio_class = ioprio >> IOPRIO_CLASS_SHIFT;
+ if (ioprio_class != IOPRIO_CLASS_IDLE) {
+ ioprio = ioprio & 0xff;
+ printf("%s: prio %d\n", to_prio[ioprio_class], ioprio);
+ } else
+ printf("%s\n", to_prio[ioprio_class]);
+ }
+}
+
int main(int argc, char *argv[])
{
int ioprio = 4, set = 0, tolerant = 0, ioprio_class = IOPRIO_CLASS_BE;
- int c, pid = 0;
+ int c, pid = 0, use_pids = 0;
+ char **a;
- while ((c = getopt(argc, argv, "+n:c:p:th")) != EOF) {
+ while ((c = getopt(argc, argv, "+n:c:pth")) != EOF) {
switch (c) {
case 'n':
ioprio = strtol(optarg, NULL, 10);
@@ -71,7 +90,7 @@ int main(int argc, char *argv[])
set |= 2;
break;
case 'p':
- pid = strtol(optarg, NULL, 10);
+ use_pids = 1;
break;
case 't':
tolerant = 1;
@@ -101,35 +120,50 @@ int main(int argc, char *argv[])
}
if (!set) {
- if (!pid && argv[optind])
- pid = strtol(argv[optind], NULL, 10);
-
- ioprio = ioprio_get(IOPRIO_WHO_PROCESS, pid);
+ if (use_pids)
+ {
+ for(a = &argv[optind]; *a; ++a)
+ {
+ pid = strtol(*a, NULL, 10);
+ ioprio_print(pid);
+ }
+ }
+ else
+ {
+ if (argv[optind])
+ pid = strtol(argv[optind], NULL, 10);
- if (ioprio == -1) {
- perror("ioprio_get");
- exit(EXIT_FAILURE);
- } else {
- ioprio_class = ioprio >> IOPRIO_CLASS_SHIFT;
- if (ioprio_class != IOPRIO_CLASS_IDLE) {
- ioprio = ioprio & 0xff;
- printf("%s: prio %d\n", to_prio[ioprio_class], ioprio);
- } else
- printf("%s\n", to_prio[ioprio_class]);
+ ioprio_print(pid);
}
} else {
- if (ioprio_set(IOPRIO_WHO_PROCESS, pid, ioprio | ioprio_class << IOPRIO_CLASS_SHIFT) == -1) {
- if (!tolerant) {
- perror("ioprio_set");
- exit(EXIT_FAILURE);
+ if (use_pids)
+ {
+ for(a = &argv[optind]; *a; ++a)
+ {
+ pid = strtol(*a, NULL, 10);
+ if (ioprio_set(IOPRIO_WHO_PROCESS, pid, ioprio | ioprio_class << IOPRIO_CLASS_SHIFT) == -1) {
+ if (!tolerant) {
+ perror("ioprio_set");
+ exit(EXIT_FAILURE);
+ }
+ }
}
}
+ else
+ {
+ if (ioprio_set(IOPRIO_WHO_PROCESS, pid, ioprio | ioprio_class << IOPRIO_CLASS_SHIFT) == -1) {
+ if (!tolerant) {
+ perror("ioprio_set");
+ exit(EXIT_FAILURE);
+ }
+ }
- if (argv[optind]) {
- execvp(argv[optind], &argv[optind]);
- /* execvp should never return */
- perror("execvp");
- exit(EXIT_FAILURE);
+ if (argv[optind]) {
+ execvp(argv[optind], &argv[optind]);
+ /* execvp should never return */
+ perror("execvp");
+ exit(EXIT_FAILURE);
+ }
}
}
--
1.5.6.3
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
[Site Home] [Netdev] [Ethernet Bridging] [Linux Wireless] [Kernel Newbies] [Memory] [Security] [Linux for Hams] [Netfilter] [Bugtraq] [Rubini] [Photo] [Yosemite] [Yosemite News] [MIPS Linux] [ARM Linux] [Linux RAID] [Linux Admin] [Samba] [Video 4 Linux] [Linux Resources]