NEXItaliano

NEX › Manual pages › nex(3)

NEX(3) NEX Programming NEX(3)

nex_conn - C library for using the NEX cluster: nodes, processes, remote execution, queue

#include <nex.h>
nex_conn *nex_open(const char *socket_path);
void nex_close(nex_conn *nd);
void nex_free(char *s);
int nex_spawn(const char *node, const char *const argv[], nex_pid *pid);
int nex_spawn_ex(const char *node, const char *const argv[], const char *cwd,
                     const char *const env[], const char *cpu, const char *mem, nex_pid *pid);
int nex_wait(const nex_pid *pid, int *status, int timeout_ms);
const char *nex_errmsg(void);
int nex_nodes(nex_conn *nd, char **response);
int nex_ps(nex_conn *nd, int cluster, char **response);
char *nex_run_json(const char *node, const char *const argv[], const char *cwd, ...);
nex_job *nex_run(nex_conn *nd, const char *request, int *err);
int nex_job_next(nex_job *job, int *event, char **data, size_t *len);
int nex_submit(nex_conn *nd, const char *node, const char *const argv[], ...);
int nex_request(nex_conn *nd, const char *request, char **response);
int nex_kv_get(nex_conn *nd, const char *space, const char *key, char **value);
int nex_kv_cas(nex_conn *nd, const char *space, const char *key, const char *expect, const char *value, int ttl);

Link with -lnex.

libnex talks to the NEX agent of the local node (nexagentd(8), socket /run/nex/agent.sock). No credentials are needed: the agent learns from the kernel who the calling process is; the process acts as its own user and sees what it would see with nex(1). Responses are JSON documents in allocated strings, to be freed with nex_free; the format stays compatible as long as the version field does not change. A nex_conn handle must not be used by several threads at the same time.

A node is given by name; NULL or "" is the local node, "any" the least loaded one. A command for another node starts in a directory under /nex.

nex_spawn starts argv as a detached job, in the current directory with the caller's PATH, LANG, LC_ALL and TZ, and returns in pid the node and the job (the same ones shown by nex jobs and nex attach). The process does not depend on the caller. nex_spawn_ex chooses the directory, the environment, and the maximum CPU ("50" = half a CPU) and memory ("512M"). nex_wait waits for the end and stores in status the exit code as the shell does (128 + signal if killed); timeout_ms -1 means no limit, 0 checks and returns (like WNOHANG). Like waitpid(2) it reaps the job. nex_errmsg gives the reason for the thread's last spawn or wait error.

nex_spawn_image, nex_run_json_image, nex_run_detached_image and nex_submit_image do the same in a rootless Podman container with an image from the cluster's archive (nex image list): same user, /nex at the same path, the node's network, the image's PATH.

nex_run_json prepares the request, nex_run sends it (the handle stays dedicated to the job), nex_job_next returns the events NEX_EV_STARTED, _STDOUT, _STDERR, _EXIT, _LOST, _ERROR; nex_job_write, nex_job_close_stdin and nex_job_signal control the remote process.

Detached jobs (nex_run_detached, nex_jobs, nex_job_stop, nex_attach_json), queue (nex_submit, nex_queue, nex_queue_cancel), signals and messages (nex_kill, nex_msg), logs (nex_logs), TCP connections seen from another node (nex_forward_json), remote graphics and audio (X11, Wayland, PulseAudio: nex_run_json_av, nex_job_pa_send) the cluster key-value store, the same from every node, with expiry and atomic compare (nex_kv_get, nex_kv_set, nex_kv_cas, nex_kv_del, nex_kv_list; personal, "group:NAME" and "cluster" spaces), the caller's encrypted secrets (nex_secret_get, nex_secret_set, nex_secret_del, nex_secret_list, nex_secret_free which zeroes the value), messages between processes (nex_pub, nex_pub_ex with NEX_PUB_NOHISTORY for messages that are not kept in the history, nex_sub_open, nex_sub_next, nex_sub_close; queues with a single consumer per message: nex_mq_push, nex_mq_pop, nex_mq_len), history of the node measurements (nex_metrics) and generic requests (nex_request). Every function is described, with examples, in the developer guide.

NEX_OK (0) on success; otherwise NEX_ERR_PARAM (-1), _CONNECT (-2, agent not reachable), _IO (-3), _AGENT (-4, request refused: the reason is in response or in nex_errmsg), _LOST (-5, job or node lost), _TIMEOUT (-6, job still running), _NOTFOUND (-7, job or key does not exist), _CONFLICT (-8, nex_kv_cas: someone else wrote first). nex_strerror gives the text.

nex_pid pid;
int st;
const char *argv[] = { "make", "-j2", NULL };
if (nex_spawn("any", argv, &pid) != NEX_OK) {

fprintf(stderr, "%s\n", nex_errmsg());
return 1; } printf("started on %s, job %s\n", pid.node, pid.job); if (nex_wait(&pid, &st, -1) == NEX_OK)
printf("finished with %d\n", st);

/usr/include/nex.h
the header, with the contract of every function.
/usr/share/doc/libnex-dev/libnex.md
the developer guide.
/usr/share/doc/libnex-dev/examples/
ten example programs, with their Makefile.

nex(1), nexagentd(8), posix_spawn(3), waitpid(2)

November 2026 libnex 0.20.0