File: libproc2-test.c

package info (click to toggle)
earlyoom 1.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 484 kB
  • sloc: ansic: 1,773; makefile: 127; sh: 94; python: 11
file content (30 lines) | stat: -rw-r--r-- 734 bytes parent folder | download | duplicates (2)
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
#include <libproc2/pids.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[])
{
    enum pids_item items[] = { PIDS_STATE };
    struct pids_info* info;
    struct pids_stack* stack;
    struct pids_fetch* fetched;

    int ret = procps_pids_new(&info, items, 1);
    if (ret != 0) {
        printf("new failured, ret=%d\n", ret);
        exit(4);
    }

    unsigned pidlist[] = { 1 };
    fetched = procps_pids_select(info, pidlist, 1, PIDS_SELECT_PID_THREADS);
    if (!fetched) {
        printf("select error\n");
        exit(3);
    }
    if (fetched->counts->total != 1) {
        exit(2);
    }
    stack = fetched->stacks[0];
    char state = PIDS_VAL(0, s_ch, stack, info);
    printf("%c\n", state);
}