|
Procster
0.1
Procster-ViewProcessesovertheweb
|
Misc Process utilities (not related to process lists or trees). More...
#include <stdio.h>#include <sys/types.h>#include <signal.h>#include <errno.h>#include <string.h>#include <jansson.h>#include "proclister.h"
Functions | |
| void | par_add_child (proc_t *par, proc_t *ch) |
| Add a child process to a parent. More... | |
| GSList * | par_get_ch (proc_t *p) |
| Get a list of direct child processes of parent process. More... | |
| int | proc_kill (int pid) |
| Kill process by sending SIGKILL signal to it. More... | |
| void | proc_st_iso (proc_t *p, char *tbuf, size_t size, int fix) |
| Convert / Format p->start_time into human readable ISO time. More... | |
| int | gsleader (proc_t *p) |
| Return Process leadership position (NONE=0, GROUP=1, SESSION=2). More... | |
| int | list2str (char **list, char buf[], int size) |
| Create approximate cmdline string out of char ** cmdline. More... | |
| json_t * | proc_to_json (proc_t *proc, char *cmdline) |
| Populate Process node into (Jansson) JSON Object. More... | |
| void | ptree_dump (proc_t *p, int lvl) |
| Dump process tree to STDOUT. More... | |
| json_t * | ptree_json (proc_t *p, int lvl) |
| Convert process tree to JSON. More... | |
| void | ptree_free (proc_t *p, int lvl) |
| Free/Release the tree of processes. More... | |
Variables | |
| char * | leadstr [] = {"", "GRPLEAD", "SESSLEAD", NULL} |
Misc Process utilities (not related to process lists or trees).
| int gsleader | ( | proc_t * | p | ) |
Return Process leadership position (NONE=0, GROUP=1, SESSION=2).
Returned int values can be converted to string labels by
| p | - process |
Referenced by ptree_dump().
| int list2str | ( | char ** | list, |
| char | buf[], | ||
| int | size | ||
| ) |
Create approximate cmdline string out of char ** cmdline.
Approximate means no quoting or escaping is done to turn char ** items back into real runnable properly formatted commandline string. Approximate is good enough for this process listing usage.
| list | - Array of Strings |
| buf | - String buffer where Array items are serialized space-separated (must contain enough space for string output) |
| size | - Size of buf (in bytes) |
Referenced by proc_to_json().
Add a child process to a parent.
Child is added to an "abused" (not meant for this purpose) struct member (however still a pointer member "lxcname") of the process structure. Facilitates appropriate casts to allow smooth operation and easy use.
| par | - Parent |
| ch | - Child |
Referenced by proc_tree().
Get a list of direct child processes of parent process.
| p | - Parent process whose direct children are being accessed |
Referenced by ptree_dump(), ptree_free(), and ptree_json().
| int proc_kill | ( | int | pid | ) |
Kill process by sending SIGKILL signal to it.
See also man 7 signal and man 2 kill.
| pid | - PID of individual process (>= 1) |
Referenced by answer_to_connection0().
| void proc_st_iso | ( | proc_t * | p, |
| char * | tbuf, | ||
| size_t | size, | ||
| int | fix | ||
| ) |
Convert / Format p->start_time into human readable ISO time.
| p | - Process Object |
| tbuf | - String buffer for ISO time |
| size | - Size for tbuf (will be forwarded to strftime()) |
| fix | - N/A (yet), pass 0 (TODO: Fix start_time to reflect EPOC time) |
References proc_stime_ux.
Referenced by ptree_dump().
Populate Process node into (Jansson) JSON Object.
Can be used to populate processes in linear list or tree formats.
| proc | - Process |
| cmdline | - Buffer to serialize (approximate) command line with arguments into. |
References list2str(), and proc_stime_ux.
Referenced by proc_list_json2(), and ptree_json().
| void ptree_dump | ( | proc_t * | p, |
| int | lvl | ||
| ) |
Dump process tree to STDOUT.
| p | - Root process of the tree |
| lvl | - Level in the process tree (Intial caller should pass 0) |
References gsleader(), leadstr, par_get_ch(), and proc_st_iso().
Referenced by proc_tree().
| void ptree_free | ( | proc_t * | p, |
| int | lvl | ||
| ) |
Free/Release the tree of processes.
Release custom used (OLD:lxcname) "sd_uunit" member (GSList *) and mark it unallocated (NULL) to not accidentally free it wrongly (or leak memory).
| p | - Root process |
| lvl | - Recursion level (explicit caller should pass 0) |
References freeproc(), g_slist_free(), par_get_ch(), and proc_chn_init.
Referenced by answer_to_connection0(), and proc_list_json2().
Convert process tree to JSON.
| p | - Root process node of the tree (linux kernel, pid=0) |
| lvl | - Recursion level (explicit caller should pass 0) |
References par_get_ch(), and proc_to_json().
Referenced by answer_to_connection0(), and proc_list_json2().
| char* leadstr[] = {"", "GRPLEAD", "SESSLEAD", NULL} |
Referenced by ptree_dump().