#include <sys/resource.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <limits.h>
#include <libgen.h>
#include <dirent.h>
#include <ctype.h>
#include <amxc/amxc.h>
#include <amxc/amxc_macros.h>
#include <amxp/amxp.h>
Go to the source code of this file.
◆ _GNU_SOURCE
◆ amxp_proci_expr_get_field()
Definition at line 75 of file amxp_proc_info.c.
82 if(strcmp(
path,
"name") == 0) {
83 amxc_var_set(cstring_t, value, pi->
name);
84 }
else if(strcmp(
path,
"parent_pid") == 0) {
86 }
else if(strcmp(
path,
"ppid") == 0) {
88 }
else if(strcmp(
path,
"state") == 0) {
89 amxc_var_set(int8_t, value, pi->
state);
enum _expr_status amxp_expr_status_t
Expression status/error codes.
@ amxp_expr_status_field_not_found
Structure containing the process information.
static amxc_string_t path
◆ amxp_proci_fill()
Definition at line 97 of file amxp_proc_info.c.
99 amxc_var_for_each(item, data) {
102 proc_info->
pid = amxc_var_dyncast(int32_t, item);
106 char* n = amxc_var_take(cstring_t, item);
107 amxc_string_init(&name, 0);
108 amxc_string_push_buffer(&name, n, n == NULL ? 0 : strlen(n) + 1);
109 amxc_string_trim(&name, ispunct);
110 proc_info->
name = amxc_string_take_buffer(&name);
114 proc_info->
state = amxc_var_dyncast(int8_t, item);
117 proc_info->
parent_pid = amxc_var_dyncast(int32_t, item);
120 proc_info->
process_gid = amxc_var_dyncast(int32_t, item);
123 proc_info->
session_id = amxc_var_dyncast(int32_t, item);
◆ amxp_proci_read_stat()
Definition at line 130 of file amxp_proc_info.c.
138 amxc_var_init(&stat);
140 fp = fopen(amxc_string_get(file, 0),
"r");
145 read = getline(&line, &len, fp);
153 amxc_var_push(ssv_string_t, &stat, line);
154 amxc_var_cast(&stat, AMXC_VAR_ID_LIST);
157 when_null(proc_info, exit);
162 amxc_var_clean(&stat);
static void amxp_proci_fill(amxp_proc_info_t *proc_info, amxc_var_t *data)
◆ amxp_proci_scan_proc()
static int amxp_proci_scan_proc |
( |
amxc_llist_t * |
procs, |
|
|
amxp_expr_t * |
expr |
|
) |
| |
|
static |
Definition at line 166 of file amxp_proc_info.c.
170 amxc_string_t filename;
174 amxc_string_init(&filename, 128);
176 dp = opendir(
"/proc/");
179 for(ep = readdir(dp); ep; ep = readdir(dp)) {
180 if(ep->d_type != DT_DIR) {
184 if(ep->d_name[0] ==
'.') {
188 amxc_string_reset(&filename);
189 amxc_string_setf(&filename,
"/proc/%s/stat", ep->d_name);
194 amxc_llist_append(procs, &pi->
it);
199 amxc_llist_append(procs, &pi->
it);
209 amxc_string_clean(&filename);
static amxp_expr_status_t amxp_proci_expr_get_field(UNUSED amxp_expr_t *expr, amxc_var_t *value, const char *path, void *priv)
static amxp_proc_info_t * amxp_proci_read_stat(amxc_string_t *file)
bool amxp_expr_evaluate(amxp_expr_t *expr, amxp_expr_get_field_t fn, void *priv, amxp_expr_status_t *status)
Evaluates an expression.
void amxp_proci_free_it(amxc_llist_it_t *it)
Delete a amxp_proc_info_t by it is linked list iterator.