-
Notifications
You must be signed in to change notification settings - Fork 0
/
rptree.h
86 lines (72 loc) · 2.15 KB
/
rptree.h
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* running process tree
*
* qianfan Zhao <[email protected]>
*/
#ifndef RPTREE_H
#define RPTREE_H
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <stdbool.h>
#include "list_head.h"
struct process {
pid_t pid;
pid_t ppid;
char cwd[1024];
char *cmdline;
size_t cmdline_len;
char *environ;
size_t environ_len;
int pipe_fd0;
int pipe_fd1;
struct timespec boottime;
struct list_head head;
struct list_head childs;
struct process *parent;
struct process *pipe_next;
/* the main program running some code and then execl */
struct process *next_exec;
uint8_t runtime_data[0];
};
struct process *get_root_process(void);
struct process *process_find(pid_t pid);
bool process_has_env(struct process *, const char *);
const char *next_string(const char *buf, size_t bufsz, const char *s);
#define foreach_string(i, buf, bufsz) \
for (i = NULL; (i = next_string(buf, bufsz, i)) != NULL; )
size_t count_string(const char *buf, size_t bufsz);
int rpshell(char *rpshell_command);
struct show_rptree_option {
bool show_env;
bool show_pipefd;
bool show_cwd;
bool show_ts;
};
void show_rptree(struct show_rptree_option *opt);
#define timespecadd(tsp, usp, vsp) \
do { \
(vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \
(vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \
if ((vsp)->tv_nsec >= 1000000000L) { \
(vsp)->tv_sec++; \
(vsp)->tv_nsec -= 1000000000L; \
} \
} while (/* CONSTCOND */ 0)
#define timespecsub(tsp, usp, vsp) \
do { \
(vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
(vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
if ((vsp)->tv_nsec < 0) { \
(vsp)->tv_sec--; \
(vsp)->tv_nsec += 1000000000L; \
} \
} while (/* CONSTCOND */ 0)
pid_t procfs_get_ppid(pid_t pid);
void *file_alloc(int fd, size_t *ret_filesize);
int procfs_read(pid_t pid, const char *name, char *buf, size_t bufsz);
void *procfs_alloc(pid_t pid, const char *name, size_t *ret_filesize);
int procfs_get_cwd(pid_t pid, char *buf, size_t bufsz);
int procfs_get_fdname(pid_t pid, int fd, char *buf, size_t bufsz);
int procfs_get_pipefd(pid_t pid, int fd);
#endif