libsysactivity  0.6.4
 All Data Structures Functions Variables Enumerations Enumerator Groups Pages
process.h
1 /*
2  * libsysactivity
3  * http://sourceforge.net/projects/libsysactivity/
4  * Copyright (c) 2009, 2010 Carlos Olmedo Escobar <carlos.olmedo.e@gmail.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
25 #ifndef SA_PROCESS_H_
26 #define SA_PROCESS_H_
27 
28 #include <sys/types.h>
29 
33 SA_EXPORT enum sa_process_state {
34  SA_UNKNOWN = 0,
35  SA_RUNNING = 1,
38  SA_ZOMBIE = 4,
39  SA_STOPPED = 5,
40 };
41 
45 SA_EXPORT struct sa_process_activity {
46 #ifdef SA_PROCESS_PID
47  pid_t pid;
48 #endif
49 #ifdef SA_PROCESS_STATE
51 #endif
52 #ifdef SA_PROCESS_USER_TIME // TODO Explain these better
53  uint64_t user_time;
54 #endif
55 #ifdef SA_PROCESS_SYS_TIME
56  uint64_t sys_time;
57 #endif
58 #ifdef SA_PROCESS_THREADS
59  uint32_t threads;
60 #endif
61 #ifdef SA_PROCESS_VM_SIZE
62  uint32_t vm_size;
63 #endif
64 #ifdef SA_PROCESS_RSS
65  uint32_t rss;
66 #endif
67 };
68 
72 SA_EXPORT struct sa_process {
73 #ifdef SA_PROCESS_PID
74  pid_t pid;
75 #endif
76 #ifdef SA_PROCESS_UID
77  uid_t uid;
78 #endif
79 #ifdef SA_PROCESS_GID
80  gid_t gid;
81 #endif
82 #ifdef SA_PROCESS_FILENAME
83  char filename[SA_PROCESS_FILENAME];
84 #endif
85 #ifdef SA_PROCESS_CMDLINE
86  char cmdline[SA_PROCESS_CMDLINE];
87 #endif
88 #ifdef SA_PROCESS_PARENT_PID
89  pid_t parent_pid;
90 #endif
91 #ifdef SA_PROCESS_PGRP
92  pid_t pgrp;
93 #endif
94 #ifdef SA_PROCESS_SID
95  pid_t sid;
96 #endif
97 #ifdef SA_PROCESS_TTY
98  pid_t tty;
99 #endif
100 #ifdef SA_PROCESS_NICE
101  int8_t nice;
102 #endif
103 #ifdef SA_PROCESS_START_TIME
104  uint64_t start_time;
105 #endif
106 struct sa_process_activity activity;
107 };
108 
109 #ifdef SA_OPEN_PROCESS
110 
115 int sa_open_process() SA_EXPORT;
116 #endif
117 
118 #ifdef SA_CLOSE_PROCESS
119 
124 int sa_close_process() SA_EXPORT;
125 #endif
126 
132 int sa_count_processes(uint32_t* number) SA_EXPORT SA_NONNULL;
133 
142 int sa_get_processes_ids(pid_t* dst, uint32_t dst_size, uint32_t* written) SA_EXPORT SA_NONNULL;
143 
150 int sa_get_process(pid_t pid, struct sa_process* dst) SA_EXPORT SA_NONNULL;
151 
159 int sa_get_process_activity(pid_t pid, struct sa_process_activity* dst) SA_EXPORT SA_NONNULL;
160 
162 #endif /* SA_PROCESS_H_ */