forked from shinh/test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_output.c
36 lines (31 loc) · 831 Bytes
/
check_output.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
int main() {
char buf[256];
printf("%d\n", readlink("/proc/self/fd/1", buf, 255));
printf("%s\n", buf);
printf("PID=%d\n", getpid());
pid_t parent = getppid();
printf("PPID=%d\n", parent);
sprintf(buf, "/proc/%d/task", parent);
DIR* dir = opendir(buf);
struct dirent* ent;
/*
while ((ent = readdir(dir)) != NULL) {
printf("%s\n", ent->d_name);
}
*/
pid_t mygrp = getpgrp();
dir = opendir("/proc");
while ((ent = readdir(dir)) != NULL) {
int pid = atoi(ent->d_name);
if (!pid) continue;
pid_t grp = getpgid(pid);
if (grp == mygrp) {
printf("%d %d\n", pid, grp);
}
}
printf("tcgetpgrp(1) = %d\n", tcgetpgrp(1));
}