Mercurial > hg > toybox
annotate toys/other/taskset.c @ 656:6df4ccc0acbe
Regularize command headers, update links to standards documents.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 25 Aug 2012 18:08:51 -0500 |
parents | 2986aa63a021 |
children | 7e846e281e38 |
rev | line source |
---|---|
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
1 /* vi: set sw=4 ts=4: |
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 * taskset.c - Retrieve or set the CPU affinity of a process. |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
4 * |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
5 * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com> |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
6 |
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
|
7 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
|
8 |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
9 config TASKSET |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
10 bool "taskset" |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
11 default y |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
12 help |
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
|
13 usage: taskset [-ap] [mask] [PID | cmd [args...]] |
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
|
14 |
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
|
15 Launch a new task which may only run on certain processors, or change |
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
|
16 the processor affinity of an exisitng PID. |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
17 |
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 Mask is a hex string where each bit represents a processor the process |
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
|
19 is allowed to run on. PID without a mask displays existing affinity. |
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
|
20 |
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
|
21 -p Set/get the affinity of given PID instead of a new command. |
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
|
22 -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
|
23 */ |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
24 |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
25 #include "toys.h" |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
26 |
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
|
27 #define FLAG_a 0x1 |
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
|
28 #define FLAG_p 0x2 |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
29 |
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
|
30 // Prototype for syscall wrappers sched.h refuses to give us |
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
|
31 int sched_setaffinity(pid_t pid, size_t size, void *cpuset); |
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 int sched_getaffinity(pid_t pid, size_t size, void *cpuset); |
645 | 33 |
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
|
34 // 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
|
35 // 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
|
36 |
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
|
37 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
|
38 { |
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
|
39 unsigned long *mask = (unsigned long *)toybuf; |
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 char *s = *toys.optargs, *failed = "failed to %s %d's affinity"; |
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
|
41 int i, j, k; |
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
|
42 |
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
|
43 for (i=0; ; i++) { |
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
|
44 if (!quiet) { |
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
|
45 int j = sizeof(toybuf), flag = 0; |
628
3041521db5d0
Largely cosmetic code cleanups.
Rob Landley <rob@landley.net>
parents:
627
diff
changeset
|
46 |
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
|
47 if (sched_getaffinity(pid, sizeof(toybuf), (void *)mask)) |
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
|
48 perror_exit(failed, "get", pid); |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
49 |
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
|
50 printf("pid %d's %s affinity mask: ", pid, i ? "new" : "current"); |
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
|
51 |
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
|
52 while (j--) { |
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
|
53 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
|
54 |
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
|
55 if (flag) printf("%02x", x); |
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
|
56 else if (x) { |
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
|
57 flag++; |
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
|
58 printf("%x", x); |
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
|
59 } |
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
|
60 } |
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 putchar('\n'); |
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
|
62 } |
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
|
63 |
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
|
64 if (i || toys.optc < 2) return; |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
65 |
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
|
66 memset(toybuf, 0, sizeof(toybuf)); |
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
|
67 k = strlen(s = *toys.optargs); |
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
|
68 s += k; |
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
|
69 for (j = 0; j<k; j++) { |
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
|
70 unsigned long digit = *(--s) - '0'; |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
71 |
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
|
72 if (digit > 9) digit = 10 + tolower(*s)-'a'; |
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
|
73 if (digit > 15) error_exit("bad mask '%s'", *toys.optargs); |
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
|
74 mask[j/(2*sizeof(long))] |= digit << 4*(j&((2*sizeof(long))-1)); |
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
|
75 } |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
76 |
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
|
77 if (sched_setaffinity(pid, sizeof(toybuf), (void *)mask)) |
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
|
78 perror_exit(failed, "set", pid); |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
79 } |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
80 } |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
81 |
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
|
82 static int task_callback(struct dirtree *new) |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
83 { |
628
3041521db5d0
Largely cosmetic code cleanups.
Rob Landley <rob@landley.net>
parents:
627
diff
changeset
|
84 if (!new->parent) return DIRTREE_RECURSE; |
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
|
85 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
|
86 |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
87 return 0; |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
88 } |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
89 |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
90 void taskset_main(void) |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
91 { |
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
|
92 if (!(toys.optflags & FLAG_p)) { |
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
|
93 if (toys.optc < 2) error_exit("Needs 2 args"); |
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
|
94 do_taskset(getpid(), 1); |
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
|
95 xexec(toys.optargs+1); |
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
|
96 } else { |
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
|
97 char *c; |
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
|
98 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
|
99 |
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
|
100 if (*c) error_exit("Not int %s", toys.optargs[1]); |
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
|
101 |
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
|
102 if (toys.optflags & FLAG_a) { |
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
|
103 char buf[33]; |
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
|
104 sprintf(buf, "/proc/%ld/task/", (long)pid); |
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
|
105 dirtree_read(buf, task_callback); |
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
|
106 } else do_taskset(pid, 0); |
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
|
107 } |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
108 } |