回答編集履歴
3
追記
answer
CHANGED
@@ -60,3 +60,36 @@
|
|
60
60
|
[1] 1275550
|
61
61
|
$ PID: <1275550>
|
62
62
|
```
|
63
|
+
|
64
|
+
### 追記
|
65
|
+
|
66
|
+
> 一度にPIDS_ID_PPID, PIDS_CMDを取得できる方法があれば
|
67
|
+
|
68
|
+
その場合は `item` に `PIDS_ID_PPID` と `PIDS_CMD` を指定します。また、項目が2個になりますので `procps_pids_new()` の第3パラメータには `2` を指定します。
|
69
|
+
フェッチしたデータは `pidread->stacks[0]->head[0]` が `PIDS_ID_PPID` に、`pidread->stacks[0]->head[1]` が `PIDS_CMD` に対応しています。
|
70
|
+
|
71
|
+
```c
|
72
|
+
#include <stdio.h>
|
73
|
+
#include <unistd.h>
|
74
|
+
#include <stdlib.h>
|
75
|
+
#include <libproc2/pids.h>
|
76
|
+
#include <string.h>
|
77
|
+
|
78
|
+
int main(void)
|
79
|
+
{
|
80
|
+
struct pids_info *info = NULL;
|
81
|
+
enum pids_item item[] = {PIDS_ID_PPID, PIDS_CMD};
|
82
|
+
procps_pids_new(&info, item, 2);
|
83
|
+
|
84
|
+
pid_t ppid = getppid();
|
85
|
+
struct pids_fetch *pidread = NULL;
|
86
|
+
pidread = procps_pids_select(info, (unsigned int *)&ppid, 1, PIDS_SELECT_PID);
|
87
|
+
printf("PID: <%d>\n", getpid());
|
88
|
+
printf("PPID: <%d>\n", getppid());
|
89
|
+
printf("PPPID: <%d>\n", pidread->stacks[0]->head[0].result.u_int);
|
90
|
+
printf("PPPCMD: <%s>\n", pidread->stacks[0]->head[1].result.str);
|
91
|
+
fflush(stdout);
|
92
|
+
|
93
|
+
return 0;
|
94
|
+
}
|
95
|
+
```
|
2
answer
CHANGED
@@ -46,7 +46,8 @@
|
|
46
46
|
pid_t ppid = getppid();
|
47
47
|
struct pids_fetch *pidread = NULL;
|
48
48
|
pidread = procps_pids_select(info, (unsigned int *)&ppid, 1, PIDS_SELECT_PID);
|
49
|
-
printf("%d\n", pidread->stacks[0]->head->result.u_int);
|
49
|
+
printf("PID: <%d>\n", pidread->stacks[0]->head->result.u_int);
|
50
|
+
fflush(stdout);
|
50
51
|
|
51
52
|
return 0;
|
52
53
|
}
|
1
answer
CHANGED
@@ -53,7 +53,7 @@
|
|
53
53
|
```
|
54
54
|
|
55
55
|
上記のソースコードをコンパイルして実行します。
|
56
|
-
```
|
56
|
+
```bash
|
57
57
|
$ gcc -O0 -Wall -Wextra cpu_hog_sudo_version.c -lproc2
|
58
58
|
$ sudo taskset -c 0 nice -n 19 ./a.out &
|
59
59
|
[1] 1275550
|