Mercurial > hg > toybox
annotate toys/taskset.c @ 650:dd82e0b28eda
Fix bug spotted by Avery Pennarun: getusername() and getgroupname() can reuse the utoa buffer when neither is recognized, meaning uid would be shown again instead of gid.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 18 Aug 2012 21:12:02 -0500 |
parents | fb546cc2a022 |
children |
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 * |
645 | 7 * No standard. |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
8 |
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
|
9 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
|
10 |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
11 config TASKSET |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
12 bool "taskset" |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
13 default y |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
14 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
|
15 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
|
16 |
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
|
17 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
|
18 the processor affinity of an exisitng PID. |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
19 |
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
|
20 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
|
21 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
|
22 |
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
|
23 -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
|
24 -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
|
25 */ |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
26 |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
27 #include "toys.h" |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
28 |
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
|
29 #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
|
30 #define FLAG_p 0x2 |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
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 // 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
|
33 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
|
34 int sched_getaffinity(pid_t pid, size_t size, void *cpuset); |
645 | 35 |
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
|
36 // 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
|
37 // 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
|
38 |
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
|
39 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
|
40 { |
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
|
41 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
|
42 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
|
43 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
|
44 |
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 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
|
46 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
|
47 int j = sizeof(toybuf), flag = 0; |
628
3041521db5d0
Largely cosmetic code cleanups.
Rob Landley <rob@landley.net>
parents:
627
diff
changeset
|
48 |
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 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
|
50 perror_exit(failed, "get", pid); |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
51 |
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
|
52 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
|
53 |
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
|
54 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
|
55 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
|
56 |
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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 } |
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 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
|
64 } |
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
|
65 |
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 if (i || toys.optc < 2) return; |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
67 |
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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 unsigned long digit = *(--s) - '0'; |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
73 |
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
|
74 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
|
75 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
|
76 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
|
77 } |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
78 |
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
|
79 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
|
80 perror_exit(failed, "set", pid); |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
81 } |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
82 } |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
83 |
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
|
84 static int task_callback(struct dirtree *new) |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
85 { |
628
3041521db5d0
Largely cosmetic code cleanups.
Rob Landley <rob@landley.net>
parents:
627
diff
changeset
|
86 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
|
87 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
|
88 |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
89 return 0; |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
90 } |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
91 |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
92 void taskset_main(void) |
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
93 { |
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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 } 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
|
99 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
|
100 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
|
101 |
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
|
102 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
|
103 |
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 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
|
105 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
|
106 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
|
107 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
|
108 } 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
|
109 } |
627
c8330ef95d13
Adding initial implementation of taskset
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
110 } |