cctools
process.h File Reference
#include <sys/time.h>
#include <sys/types.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <errno.h>

Go to the source code of this file.

Data Structures

struct  process_info
 Describes a completed process. More...
 

Functions

struct process_infoprocess_wait (int timeout)
 Wait for a process to complete, and return its status. More...
 
struct process_infoprocess_waitpid (pid_t pid, int timeout)
 Wait for a specific process to complete and return its status. More...
 
int process_pending ()
 Detect if a child process has completed. More...
 
int process_kill_waitpid (pid_t pid, int timeout)
 Attempt to cleanly terminate process pid for timeout seconds by sending SIGTERM If the process has not returned by then, send SIGKILL to the process and attempt to wait for another timeout seconds if this is still not successfuly, stop trying and return. More...
 
void process_putback (struct process_info *p)
 Return a process_info structure to the queue. More...
 

Detailed Description

Provides a higher level interface to finding information about complete processes. Useful as a replacement for wait, waitpid and similar calls, which do not allow the caller to check for completion without permanently removing the completion notice.

Call process_pending to see if there is a recently completed process, process_wait to wait for completion with a timeout, and process_putback to put the completion back into the queue.

Function Documentation

◆ process_wait()

struct process_info* process_wait ( int  timeout)

Wait for a process to complete, and return its status.

Wait for up to timeout seconds for a child process to complete. If a process has completed, its status will be returned in a process_info structure. The caller may either call free to release the structure, or may return it via process_putback in order to allow another caller to retrieve it.

Parameters
timeoutThe time, in seconds to wait for a child to complete. If zero, do not wait at all.
Returns
A process_info structure describing the child process status, or null if no process completed in the available time.

◆ process_waitpid()

struct process_info* process_waitpid ( pid_t  pid,
int  timeout 
)

Wait for a specific process to complete and return its status.

Like process_wait, but waits for a specific pid.

◆ process_pending()

int process_pending ( )

Detect if a child process has completed.

If so, its status may be obtained without delay by calling process_wait .

Returns
True if a child process has completed.

◆ process_kill_waitpid()

int process_kill_waitpid ( pid_t  pid,
int  timeout 
)

Attempt to cleanly terminate process pid for timeout seconds by sending SIGTERM If the process has not returned by then, send SIGKILL to the process and attempt to wait for another timeout seconds if this is still not successfuly, stop trying and return.

Return value of 1 is clean exit, while a return value of 0 an error or messy exit

◆ process_putback()

void process_putback ( struct process_info p)

Return a process_info structure to the queue.

Parameters
pA process_info structure returned by process_wait.