]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
chrt: allow to use --all-tasks when retrieve info
authorKarel Zak <kzak@redhat.com>
Thu, 5 May 2011 12:23:22 +0000 (14:23 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 5 May 2011 12:23:38 +0000 (14:23 +0200)
master thread:
 $ chrt --pid $(pidof firefox)

all threads:
 $ chrt --all-tasks --pid $(pidof firefox)

Signed-off-by: Karel Zak <kzak@redhat.com>
schedutils/chrt.1
schedutils/chrt.c

index c5d87f97d9571c1a3feb48a301937ee3d3d1dbb3..89664d68015a9862c94b519ed1ead37e2e93b6d6 100644 (file)
@@ -66,7 +66,8 @@ since Linux 2.6.31.
 operate on an existing PID and do not launch a new task
 .TP
 .B -a, --all-tasks
-propagate changes to all the tasks (threads) for a given PID.
+set or retrieve the scheduling attributes of the all tasks (threads) for a
+given PID.
 .TP
 .B -b, --batch
 set scheduling policy to
index 3669ba6a8591804024322395603c44cccdde673e..fca347678d3249f57e8416195314cd5031d95c91 100644 (file)
@@ -188,7 +188,8 @@ static void show_min_max(void)
 
 int main(int argc, char *argv[])
 {
-       int i, policy = SCHED_RR, priority = 0, verbose = 0, policy_flag = 0, all_tasks = 0;
+       int i, policy = SCHED_RR, priority = 0, verbose = 0, policy_flag = 0,
+           all_tasks = 0;
        struct sched_param sp;
        pid_t pid = -1;
 
@@ -268,7 +269,18 @@ int main(int argc, char *argv[])
                show_usage(EXIT_FAILURE);
 
        if ((pid > -1) && (verbose || argc - optind == 1)) {
-               show_rt_info(pid, FALSE);
+               if (all_tasks) {
+                       pid_t tid;
+                       struct proc_tasks *ts = proc_open_tasks(pid);
+
+                       if (!ts)
+                               err(EXIT_FAILURE, "cannot obtain the list of tasks");
+                       while (!proc_next_tid(ts, &tid))
+                               show_rt_info(tid, FALSE);
+                       proc_close_tasks(ts);
+               } else
+                       show_rt_info(pid, FALSE);
+
                if (argc - optind == 1)
                        return EXIT_SUCCESS;
        }
@@ -296,11 +308,9 @@ int main(int argc, char *argv[])
 
                if (!ts)
                        err(EXIT_FAILURE, "cannot obtain the list of tasks");
-
                while (!proc_next_tid(ts, &tid))
                        if (sched_setscheduler(tid, policy, &sp) == -1)
                                err(EXIT_FAILURE, _("failed to set tid %d's policy"), tid);
-
                proc_close_tasks(ts);
        }
        else