Mercurial > hg > toybox
annotate toys/other/taskset.c @ 1776:7bf68329eb3b draft default tip
Repository switched to git at https://github.com/landley/toybox
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 09 Apr 2015 02:28:32 -0500 |
parents | cbb1aca81eca |
children |
rev | line source |
---|---|
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
1 /* taskset.c - Retrieve or set the CPU affinity of a process. |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
2 * |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
3 * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com> |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
4 |
646
fb546cc2a022
Rewrite taskset to use syscall directly without macros/prototypes glibc refuses to make available without yet more wacky inappropriate #defines. (Linux is not the hurd.)
Rob Landley <rob@landley.net>
parents:
645
diff
changeset
|
5 USE_TASKSET(NEWTOY(taskset, "<1^pa", TOYFLAG_BIN|TOYFLAG_STAYROOT)) |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
6 |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
7 config TASKSET |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
8 bool "taskset" |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
9 default y |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
10 help |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
11 usage: taskset [-ap] [mask] [PID | cmd [args...]] |
646
fb546cc2a022
Rewrite taskset to use syscall directly without macros/prototypes glibc refuses to make available without yet more wacky inappropriate #defines. (Linux is not the hurd.)
Rob Landley <rob@landley.net>
parents:
645
diff
changeset
|
12 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
13 Launch a new task which may only run on certain processors, or change |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
14 the processor affinity of an exisitng PID. |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
15 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
16 Mask is a hex string where each bit represents a processor the process |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
17 is allowed to run on. PID without a mask displays existing affinity. |
646
fb546cc2a022
Rewrite taskset to use syscall directly without macros/prototypes glibc refuses to make available without yet more wacky inappropriate #defines. (Linux is not the hurd.)
Rob Landley <rob@landley.net>
parents:
645
diff
changeset
|
18 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
19 -p Set/get the affinity of given PID instead of a new command. |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
20 -a Set/get the affinity of all threads of the PID. |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
21 */ |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
22 |
674
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
23 #define FOR_taskset |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
24 #include "toys.h" |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
25 |
734
7e0cea8fbc3e
Use sched_{set,get}affinity directly so musl doesn't have to provide wrappers.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
26 #include <sys/syscall.h> |
7e0cea8fbc3e
Use sched_{set,get}affinity directly so musl doesn't have to provide wrappers.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
27 #define sched_setaffinity(pid, size, cpuset) \ |
7e0cea8fbc3e
Use sched_{set,get}affinity directly so musl doesn't have to provide wrappers.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
28 syscall(__NR_sched_setaffinity, (pid_t)pid, (size_t)size, (void *)cpuset) |
7e0cea8fbc3e
Use sched_{set,get}affinity directly so musl doesn't have to provide wrappers.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
29 #define sched_getaffinity(pid, size, cpuset) \ |
7e0cea8fbc3e
Use sched_{set,get}affinity directly so musl doesn't have to provide wrappers.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
30 syscall(__NR_sched_getaffinity, (pid_t)pid, (size_t)size, (void *)cpuset) |
645 | 31 |
646
fb546cc2a022
Rewrite taskset to use syscall directly without macros/prototypes glibc refuses to make available without yet more wacky inappropriate #defines. (Linux is not the hurd.)
Rob Landley <rob@landley.net>
parents:
645
diff
changeset
|
32 // mask is an array of long, which makes the layout a bit weird on big |
fb546cc2a022
Rewrite taskset to use syscall directly without macros/prototypes glibc refuses to make available without yet more wacky inappropriate #defines. (Linux is not the hurd.)
Rob Landley <rob@landley.net>
parents:
645
diff
changeset
|
33 // endian systems but as long as it's consistent... |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
34 |
634
8f22dbddf1e6
taskset.c now also support executing new commands with a given cpu affinity mask
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
628
diff
changeset
|
35 static void do_taskset(pid_t pid, int quiet) |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
36 { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
37 unsigned long *mask = (unsigned long *)toybuf; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
38 char *s = *toys.optargs, *failed = "failed to %s %d's affinity"; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
39 int i, j, k; |
646
fb546cc2a022
Rewrite taskset to use syscall directly without macros/prototypes glibc refuses to make available without yet more wacky inappropriate #defines. (Linux is not the hurd.)
Rob Landley <rob@landley.net>
parents:
645
diff
changeset
|
40 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
41 for (i=0; ; i++) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
42 if (!quiet) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
43 int j = sizeof(toybuf), flag = 0; |
628
3041521db5d0
Largely cosmetic code cleanups.
Rob Landley <rob@landley.net>
parents:
627
diff
changeset
|
44 |
734
7e0cea8fbc3e
Use sched_{set,get}affinity directly so musl doesn't have to provide wrappers.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
45 if (-1 == sched_getaffinity(pid, sizeof(toybuf), (void *)mask)) |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
46 perror_exit(failed, "get", pid); |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
47 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
48 printf("pid %d's %s affinity mask: ", pid, i ? "new" : "current"); |
646
fb546cc2a022
Rewrite taskset to use syscall directly without macros/prototypes glibc refuses to make available without yet more wacky inappropriate #defines. (Linux is not the hurd.)
Rob Landley <rob@landley.net>
parents:
645
diff
changeset
|
49 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
50 while (j--) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
51 int x = 255 & (mask[j/sizeof(long)] >> (8*(j&(sizeof(long)-1)))); |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
52 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
53 if (flag) printf("%02x", x); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
54 else if (x) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
55 flag++; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
56 printf("%x", x); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
57 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
58 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
59 putchar('\n'); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
60 } |
646
fb546cc2a022
Rewrite taskset to use syscall directly without macros/prototypes glibc refuses to make available without yet more wacky inappropriate #defines. (Linux is not the hurd.)
Rob Landley <rob@landley.net>
parents:
645
diff
changeset
|
61 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
62 if (i || toys.optc < 2) return; |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
63 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
64 memset(toybuf, 0, sizeof(toybuf)); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
65 k = strlen(s = *toys.optargs); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
66 s += k; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
67 for (j = 0; j<k; j++) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
68 unsigned long digit = *(--s) - '0'; |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
69 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
70 if (digit > 9) digit = 10 + tolower(*s)-'a'; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
71 if (digit > 15) error_exit("bad mask '%s'", *toys.optargs); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
72 mask[j/(2*sizeof(long))] |= digit << 4*(j&((2*sizeof(long))-1)); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
73 } |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
74 |
734
7e0cea8fbc3e
Use sched_{set,get}affinity directly so musl doesn't have to provide wrappers.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
75 if (-1 == sched_setaffinity(pid, sizeof(toybuf), (void *)mask)) |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
76 perror_exit(failed, "set", pid); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
77 } |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
78 } |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
79 |
646
fb546cc2a022
Rewrite taskset to use syscall directly without macros/prototypes glibc refuses to make available without yet more wacky inappropriate #defines. (Linux is not the hurd.)
Rob Landley <rob@landley.net>
parents:
645
diff
changeset
|
80 static int task_callback(struct dirtree *new) |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
81 { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
82 if (!new->parent) return DIRTREE_RECURSE; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
83 if (isdigit(*new->name)) do_taskset(atoi(new->name), 0); |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
84 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
85 return 0; |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
86 } |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
87 |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
88 void taskset_main(void) |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
89 { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
90 if (!(toys.optflags & FLAG_p)) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
91 if (toys.optc < 2) error_exit("Needs 2 args"); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
92 do_taskset(getpid(), 1); |
1676
cbb1aca81eca
Make toy_exec() check if argc is in optargs and deal with it there so we don't need a separate xexec_optargs().
Rob Landley <rob@landley.net>
parents:
955
diff
changeset
|
93 xexec(toys.optargs+1); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
94 } else { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
95 char *c; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
96 pid_t pid = strtol(toys.optargs[toys.optc-1], &c, 10); |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
97 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
98 if (*c) error_exit("Not int %s", toys.optargs[1]); |
646
fb546cc2a022
Rewrite taskset to use syscall directly without macros/prototypes glibc refuses to make available without yet more wacky inappropriate #defines. (Linux is not the hurd.)
Rob Landley <rob@landley.net>
parents:
645
diff
changeset
|
99 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
100 if (toys.optflags & FLAG_a) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
101 char buf[33]; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
102 sprintf(buf, "/proc/%ld/task/", (long)pid); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
103 dirtree_read(buf, task_callback); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
104 } else do_taskset(pid, 0); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
105 } |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
106 } |