|
Procster
0.1
Procster-ViewProcessesovertheweb
|
Initial prototyping functions to create JSON process listings. More...
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <jansson.h>#include "proclister.h"
Macros | |
| #define | IS_KTHREAD(proc) (proc.ppid <= 2) |
Functions | |
| int | arr2json (char **arr, int cnt) |
| char * | proc_list_json (int flags) |
| Create a process list directly from readproc() listing as JSON. More... | |
| json_t * | proc_list_json2 (int flags) |
| Create Process list JSON. More... | |
Initial prototyping functions to create JSON process listings.
Includes a small CLI testbench for testing output (to stdout).
... on (Ubuntu/Debian):
sudo apt-get install libpropcs-dev g++ -o proctest proctest.c -lprocps \ gcc -o proctest proctest.c -lprocps
Store process list to a file:
./proctest list > procs.json
See proc_t structure def in proc/readproc.h (/usr/include/proc/readproc.h):
Validate JSON output:
Naming comes from
See https://gitlab.com/procps-ng/procps/-/blob/master/ps/output.c Possibly do:
time_t t = getbtime() + pp->start_time / Hertz;
| #define IS_KTHREAD | ( | proc | ) | (proc.ppid <= 2) |
Referenced by proc_list_json(), and proc_list_json2().
| int arr2json | ( | char ** | arr, |
| int | cnt | ||
| ) |
| char* proc_list_json | ( | int | flags | ) |
Create a process list directly from readproc() listing as JSON.
For flags see FLAGS in man openproc.
| flags | The openproc() flags that define the extent of parsing process info from /proc/$PID (There are ~ 20 flags available). |
Make process attibutes more configurable. Possibly corralate fields to generate to flags passed as input (need lookup tables for those).
Possibly wrap response with additional JSON object to be able to convey status and error messages.
References IS_KTHREAD, and PROC_FLAGS_DEFAULT.
| json_t* proc_list_json2 | ( | int | flags | ) |
Create Process list JSON.
Serialization is done using Jansson JSON library by building AoO and serializing it. The linear list of processes can be built using single stack based process entry buffer.
| flags | - Flags for openproc() (See man openproc) |
References IS_KTHREAD, main(), proc_chn_init, PROC_FLAGS_DEFAULT, proc_list_json2(), proc_to_json(), proc_tree(), ptree_free(), and ptree_json().
Referenced by answer_to_connection0(), and proc_list_json2().