-
Notifications
You must be signed in to change notification settings - Fork 7
/
libpstat.c
92 lines (67 loc) · 2.25 KB
/
libpstat.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
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
87
88
89
90
91
92
/*
libpstat: a library for getting information about running processes
Copyright (C) 2014 Jude Nelson
This program is dual-licensed: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3 or later as
published by the Free Software Foundation. For the terms of this
license, see LICENSE.LGPLv3+ or <http://www.gnu.org/licenses/>.
You are free to use this program under the terms of the GNU Lesser General
Public License, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
Alternatively, you are free to use this program under the terms of the
Internet Software Consortium License, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
For the terms of this license, see LICENSE.ISC or
<http://www.isc.org/downloads/software-support-policy/isc-license/>.
*/
#include "libpstat.h"
#ifdef _LINUX
#include "os/linux.h"
#endif
#ifdef _UNKNOWN
#error "Undefined OS target"
#endif
// insert more OSs here
uint64_t pstat_supported_features() {
return pstat_os_supported_features();
}
// allocate a new pstat
struct pstat* pstat_new() {
return (struct pstat*)calloc( sizeof(struct pstat), 1 );
}
// free a pstat
void pstat_free( struct pstat* ps ) {
free( ps );
}
// get the status of a running processes
// return 0 on success
// return negative on error
int pstat( pid_t pid, struct pstat* ps, int flags ) {
return pstat_os( pid, ps, flags );
}
pid_t pstat_get_pid( struct pstat* ps ) {
return ps->pid;
}
bool pstat_is_running( struct pstat* ps ) {
return ps->running;
}
bool pstat_is_deleted( struct pstat* ps ) {
return ps->deleted;
}
int pstat_get_path( struct pstat* ps, char* pathbuf ) {
if( pathbuf != NULL ) {
strcpy( pathbuf, ps->path );
}
return (int)strlen( ps->path );
}
int pstat_get_stat( struct pstat* ps, struct stat* sb ) {
if( !ps->running ) {
return -ENODATA;
}
memcpy( sb, &ps->bin_stat, sizeof(struct stat) );
return 0;
}
uint64_t pstat_get_starttime( struct pstat* ps ) {
return ps->starttime;
}