1 // Try to print the cmdlines of all process spawns by polling /proc.
11 static unsigned int active[65536];
13 // assumes that *str can't be empty
14 static int str_to_int(char *str) {
17 if (*str < '0' || *str > '9') return -1;
20 if (*str == '\0') return res;
25 int main(int argc, char *argv[]) {
26 for (int i=0; i<65536; i++) {
31 DIR *dir = opendir(".");
32 unsigned int cycle = 2, lastcycle;
37 while ((dent = readdir(dir)) != NULL) {
38 int name_id = str_to_int(dent->d_name);
39 if (name_id < 0 || name_id > 65535) continue;
40 if (active[name_id] != lastcycle) {
41 sprintf(path, "%s/cmdline", dent->d_name);
42 int fd = open(path, O_RDONLY);
45 int cmdline_len = read(fd, cmdline, 65536);
46 if (cmdline_len != -1) {
47 write(1, cmdline, cmdline_len);
53 active[name_id] = cycle;