libamxp  1.4.0
Patterns C Implementation
Process Information

Data Structures

struct  _proc_info
 Structure containing the process information. More...
 

Typedefs

typedef struct _proc_info amxp_proc_info_t
 Structure containing the process information. More...
 

Functions

void amxp_proci_free_it (amxc_llist_it_t *it)
 Delete a amxp_proc_info_t by it is linked list iterator. More...
 
int amxp_proci_findf (amxc_llist_t *result, const char *filter,...)
 Build a linked list of running processes. More...
 

Detailed Description

Process information

Typedef Documentation

◆ amxp_proc_info_t

typedef struct _proc_info amxp_proc_info_t

Structure containing the process information.

Function Documentation

◆ amxp_proci_findf()

int amxp_proci_findf ( amxc_llist_t *  result,
const char *  filter,
  ... 
)

Build a linked list of running processes.

This function scans /proc/<pid>/ and allocates a amxp_proc_info_t structure for each found process.

Optionally a expression filter can be provided. The fields allowed in the filter are:

  • name
  • parent_pid or ppid
  • state
Parameters
resultpointer to a linked list, found processes will be added to this list
filteran expression that is used to filter the found processes.
Returns
0 when successful, otherwise an error code

Definition at line 219 of file amxp_proc_info.c.

219  {
220  int retval = -1;
221  amxc_string_t expression;
222  va_list args;
223  amxp_expr_t expr;
224 
225  amxc_string_init(&expression, 0);
226  when_null(result, exit);
227 
228  if(filter != NULL) {
229  va_start(args, filter);
230  amxc_string_vsetf(&expression, filter, args);
231  va_end(args);
232  when_failed(amxp_expr_init(&expr, amxc_string_get(&expression, 0)), exit);
233  }
234 
235 
236  retval = amxp_proci_scan_proc(result, filter == NULL ? NULL : &expr);
237 
238 exit:
239  if(filter != NULL) {
240  amxp_expr_clean(&expr);
241  }
242  amxc_string_clean(&expression);
243  return retval;
244 }
static int amxp_proci_scan_proc(amxc_llist_t *procs, amxp_expr_t *expr)
void amxp_expr_clean(amxp_expr_t *expr)
Clean-up the expression structure.
amxp_expr_status_t amxp_expr_init(amxp_expr_t *expr, const char *expression)
Initializes an expression structure.

◆ amxp_proci_free_it()

void amxp_proci_free_it ( amxc_llist_it_t *  it)

Delete a amxp_proc_info_t by it is linked list iterator.

Frees the structure and its content.

This function is typically used as a callback function when cleaning a linked list of amxp_proc_info_t structures.

Parameters
itthe linked list iterator of a amxp_proc_info_t instance

Definition at line 213 of file amxp_proc_info.c.

213  {
214  amxp_proc_info_t* pi = amxc_container_of(it, amxp_proc_info_t, it);
215  free(pi->name);
216  free(pi);
217 }
Structure containing the process information.