P_net_async_bgproc 3porty 2013-03-25 libporty manual

NAME

P_net_async_bgproc

SYNPOSIS

#include <libporty/net_async/abgproc.h>

int P_net_async_bgproc (char * argv [], P_net_socket * ctrlfd , P_net_socket * stdin , P_net_socket * stdout );
int P_net_async_bgproc_inherit (char * argv [], P_net_socket * ctrlfd , P_net_socket * parent_fds , int * child_fds , int inherit_len );

Link with -lporty_net_async

DESCRIPTION

P_net_async_bgproc returns non-blocking pollable sockets to a newly started background process in stdin and stout . argv is an array of arguments terminated by a NULL element; the first element (argv[0]) is the path to the executable. The caller should not assume a shell to be started. Full paths shall be used.

If the optional argument ctrlfd is provided, a third, non-blocking control socket is created. Sending string "TERM" or "KILL" on a single line will terminate or kill the process. The difference is that kill is a more drastic approach, not giving room for the background process to gracefully exit (signal 9 on UNIX). Reading the control socket will result in "START" for process startup and "END reason code" when the background process ends. Reason is one of "EXIT" (for clean exiting, code is the exit code), "ABNR" for abnormal exit (abort, or other non-caller-triggered signals) and "KILL" as a result of "TERM" or "KILL request from the application.

P_net_async_bgproc will close all file descriptors before executing argv in the child process, except for stdin/stdout (which are bound to sock and stderr, which is inherited from the parent process).

P_net_async_bgproc_inherit implements the same async background process mechanism with extra control over the file descriptors (sockets) of the child process: a set of file/socket descriptors will be inherited. Each fd in parent_fds will be inherited as the corresponding fd in child_fds . Both lists have inherit_len elements.

P_net_async_bgproc_inherit does not close any socket on the parent side, the caller is responsible to close those sockets that shall be left open only by the child process, after the call.

RETURN VALUE

Returns 0 on success or an error code from P_net_err n failure.

P_net_async_bgproc 3porty 2013-03-25 libporty manual