paraslash Paraslash Audio Streaming
About   News   Download   Documentation   Development

Functions
exec.c File Reference

Helper functions for spawning new processes. More...

#include <regex.h>
#include "para.h"
#include "error.h"
#include "fd.h"
#include "string.h"

Functions

int para_exec_cmdline_pid (pid_t *pid, const char *cmdline, int *fds)
 Execute a file as a background process, honoring $PATH. More...
 

Detailed Description

Helper functions for spawning new processes.

Function Documentation

◆ para_exec_cmdline_pid()

int para_exec_cmdline_pid ( pid_t *  pid,
const char *  cmdline,
int *  fds 
)

Execute a file as a background process, honoring $PATH.

Parameters
pidContains the PID of the child process on return.
cmdlinePath to the file to execute, followed by arguments.
fdsA pointer to a value-result array.

This function first splits the command line argument by calling create_argv(), then calls fork(2) to create a new process. The parent returns without waiting for the child to terminate. The child calls execvp(2) to replace itself with the process image that corresponds to the first word of the given command line.

The fd pointer must point to an array of three integers. Initially, the integers specify how to deal with fd 0, 1, 2 in the child:

 - < 0: Leave fd alone.
 - == 0: Dup fd to /dev/null.
 - > 0: Create a pipe and dup to one end of that pipe.

In the third case, the corresponding integer in the fd array is set to the file descriptor of the pipe that has been created. In any case, all unneeded file descriptors are closed.

Returns
Standard.
See also
null(4), pipe(2), dup2(2), fork(2), exec(3).

References create_argv().