libite
Functions
runbg.c File Reference
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
Include dependency graph for runbg.c:

Functions

int runbg (char *const cmd[], int delay)
 Run command in the background. More...
 

Detailed Description

Author
Joachim Wiberg
Date
2023

Function Documentation

◆ runbg()

int runbg ( char *const  cmd[],
int  delay 
)

Run command in the background.

Parameters
cmdNULL terminated list of command and optional arguments
delayMicroseconds after fork() to wait before calling cmd

This function forks to run the given command cmd in the background. To ensure there are no lingering zombies the function actuall forks twice, and also calls setsid(), before it calls usleep() with the delay argument. The command cmd is handed over to execvp().

Since it runs in the background it is not possible to get the return code of the command.

Returns
on successful (first) fork(), this function returns POSIX OK(0), otherwise -1 and errno is set to indicate the error.