SETINIT(2)

NAME
setinit - become and locate init

SYNOPSIS
#include <unistd.h>
pid_t
getinit(pid_t pid);
pid_t
setinit(void);

DESCRIPTION
setinit() sets the current process as the init process for itself and its subsequently created descendant processes. setinit() runs setsid(2) to create a new session (and process group) and can fail for the same reasons as setsid(2).

getinit() returns the init process for the process specified in pid, or the current process if pid is zero.

Orphaned descendant processes are reparented to their init process. If an init process exits, all descendant processes atomically receive the SIGKILL signal and become unable to create new processes and threads.

RETURN VALUES
setinit() returns the pid of the init process (the current process) on success, or -1 on error and error is set appropriately.

getinit() returns the returns the pid of the init process, or -1 on error and error is set appropriately.

ERRORS
setinit() will fail if:

EPERM
    The process is already a process group leader, a session leader, or an init process.

getinit() will fail if:

ESRCH
    The process specified in pid does not exist.

SEE ALSO
getpgrp(2), getsid(2), psctl(2), setpgrp(2), setsid(2), init(8)

HISTORY
The getinit() and setinit() system calls originally appeared in Sortix 1.1.