Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/miscutils/chrt.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/miscutils/chrt.c
r2725 r3232 6 6 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 7 7 */ 8 9 //usage:#define chrt_trivial_usage 10 //usage: "[-prfom] [PRIO] [PID | PROG ARGS]" 11 //usage:#define chrt_full_usage "\n\n" 12 //usage: "Change scheduling priority and class for a process\n" 13 //usage: "\n -p Operate on PID" 14 //usage: "\n -r Set SCHED_RR class" 15 //usage: "\n -f Set SCHED_FIFO class" 16 //usage: "\n -o Set SCHED_OTHER class" 17 //usage: "\n -m Show min/max priorities" 18 //usage: 19 //usage:#define chrt_example_usage 20 //usage: "$ chrt -r 4 sleep 900; x=$!\n" 21 //usage: "$ chrt -f -p 3 $x\n" 22 //usage: "You need CAP_SYS_NICE privileges to set scheduling attributes of a process" 23 8 24 #include <sched.h> 9 25 #include "libbb.h" … … 54 70 int policy = SCHED_RR; 55 71 56 /* at least 1 arg;only one policy accepted */57 opt_complementary = " -1:r--fo:f--ro:r--fo";72 /* only one policy accepted */ 73 opt_complementary = "r--fo:f--ro:o--rf"; 58 74 opt = getopt32(argv, "+mprfo"); 75 if (opt & OPT_m) { /* print min/max and exit */ 76 show_min_max(SCHED_FIFO); 77 show_min_max(SCHED_RR); 78 show_min_max(SCHED_OTHER); 79 fflush_stdout_and_exit(EXIT_SUCCESS); 80 } 59 81 if (opt & OPT_r) 60 82 policy = SCHED_RR; … … 63 85 if (opt & OPT_o) 64 86 policy = SCHED_OTHER; 65 if (opt & OPT_m) { /* print min/max */66 show_min_max(SCHED_FIFO);67 show_min_max(SCHED_RR);68 show_min_max(SCHED_OTHER);69 fflush_stdout_and_exit(EXIT_SUCCESS);70 }71 87 72 88 argv += optind; 89 if (!argv[0]) 90 bb_show_usage(); 73 91 if (opt & OPT_p) { 74 92 pid_str = *argv++; … … 91 109 pol = sched_getscheduler(pid); 92 110 if (pol < 0) 93 bb_perror_msg_and_die("can't %cet pid %d's policy", 'g', pid);111 bb_perror_msg_and_die("can't %cet pid %d's policy", 'g', (int)pid); 94 112 printf("pid %d's %s scheduling policy: %s\n", 95 113 pid, current_new, policies[pol].name); 96 114 if (sched_getparam(pid, &sp)) 97 bb_perror_msg_and_die("can't get pid %d's attributes", pid);115 bb_perror_msg_and_die("can't get pid %d's attributes", (int)pid); 98 116 printf("pid %d's %s scheduling priority: %d\n", 99 pid, current_new, sp.sched_priority);117 (int)pid, current_new, sp.sched_priority); 100 118 if (!*argv) { 101 119 /* Either it was just "-p <pid>", … … 116 134 117 135 if (sched_setscheduler(pid, policy, &sp) < 0) 118 bb_perror_msg_and_die("can't %cet pid %d's policy", 's', pid);136 bb_perror_msg_and_die("can't %cet pid %d's policy", 's', (int)pid); 119 137 120 138 if (!argv[0]) /* "-p <priority> <pid> [...]" */
Note:
See TracChangeset
for help on using the changeset viewer.