[prev in list] [next in list] [prev in thread] [next in thread] 

List:       util-linux-ng
Subject:    [PATCH] Let ionice -p handle multiple PIDs
From:       Stephan Maka <stephan () spaceboyz ! net>
Date:       2008-08-20 21:51:55
Message-ID: 20080820215155.GD660 () chronos ! sin
[Download RAW message or body]

Makes ionice -p usable like renice, this time backwards compatible

Signed-off-by: Stephan Maka <stephan@spaceboyz.net>
---
 schedutils/ionice.1 |    6 ++--
 schedutils/ionice.c |   76 +++++++++++++++++++++++++++++++++++----------------
 2 files changed, 55 insertions(+), 27 deletions(-)

diff --git a/schedutils/ionice.1 b/schedutils/ionice.1
index a434572..67fbc1d 100644
--- a/schedutils/ionice.1
+++ b/schedutils/ionice.1
@@ -41,7 +41,7 @@ The scheduling class data. This defines the class data, if the \
class  accepts an argument. For real time and best-effort, \fI0-7\fR is valid
 data.
 .IP "\fB-p \fIpid\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.
 .IP "\fB-t\fP"
@@ -60,9 +60,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 -p 89
+# \fBionice\fP -p 89 91
 .TP 7
-Returns the class and priority of the process with PID 89.
+Prints the class and priority of the processes with PID 89 and 91.
 
 .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 395509b..71cdec0 100644
--- a/schedutils/ionice.c
+++ b/schedutils/ionice.c
@@ -45,6 +45,23 @@ enum {
 
 const char *to_prio[] = { "none", "realtime", "best-effort", "idle", };
 
+static void ioprio_print(int pid)
+{
+        int ioprio, ioprio_class;
+        ioprio = ioprio_get(IOPRIO_WHO_PROCESS, pid);
+        
+        if (ioprio == -1)
+                err(EXIT_FAILURE, _("ioprio_get failed"));
+        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]);
+        }
+}
+
 static void usage(int rc)
 {
 	fprintf(stdout, _(
@@ -109,32 +126,43 @@ int main(int argc, char *argv[])
 	}
 
 	if (!set) {
-		if (!pid && argv[optind])
-			pid = strtol(argv[optind], NULL, 10);
+		if (pid)
+                        ioprio_print(pid);
 
-		ioprio = ioprio_get(IOPRIO_WHO_PROCESS, pid);
-
-		if (ioprio == -1)
-			err(EXIT_FAILURE, _("ioprio_get failed"));
-		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]);
-		}
+                for(; argv[optind]; ++optind)
+                {
+			pid = strtol(argv[optind], NULL, 10);
+                        ioprio_print(pid);
+                }
 	} else {
-		if (ioprio_set(IOPRIO_WHO_PROCESS, pid, ioprio | ioprio_class << \
                IOPRIO_CLASS_SHIFT) == -1) {
-			if (!tolerant)
-				err(EXIT_FAILURE, _("ioprio_set failed"));
-		}
-
-		if (argv[optind]) {
-			execvp(argv[optind], &argv[optind]);
-			/* execvp should never return */
-			err(EXIT_FAILURE, _("execvp failed"));
-		}
+                if (pid)
+                {
+                        if (ioprio_set(IOPRIO_WHO_PROCESS, pid, ioprio | \
ioprio_class << IOPRIO_CLASS_SHIFT) == -1) { +                                if \
(!tolerant) +                                        err(EXIT_FAILURE, _("ioprio_set \
failed")); +                        }
+                        for(; argv[optind]; ++optind)
+                        {
+                                pid = strtol(argv[optind], NULL, 10);
+                                if (ioprio_set(IOPRIO_WHO_PROCESS, pid, ioprio | \
ioprio_class << IOPRIO_CLASS_SHIFT) == -1) { +                                        \
if (!tolerant) +                                                err(EXIT_FAILURE, \
_("ioprio_set failed")); +                                }
+                        }
+                }
+                else
+                {
+                        if (ioprio_set(IOPRIO_WHO_PROCESS, 0, ioprio | ioprio_class \
<< IOPRIO_CLASS_SHIFT) == -1) { +                                if (!tolerant)
+                                        err(EXIT_FAILURE, _("ioprio_set failed"));
+                        }
+
+                        if (argv[optind]) {
+                                execvp(argv[optind], &argv[optind]);
+                                /* execvp should never return */
+                                err(EXIT_FAILURE, _("execvp failed"));
+                        }
+                }
 	}
 
 	exit(EXIT_SUCCESS);
-- 
1.5.6.3

--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic