Skip to content

SysProc

SysProc

Description

Opaque platform-dependent handle storing process information.

Usage example (Cross-references)

Usage examples (Cross-references)
    #endif
    
    struct SysProc {
        int  exit_code;
        bool completed;
        HANDLE              hStderrRead;
    #else
    #    error "Unsupported OS for SysProc"
    #endif
    };
    #define WRITE_END 1
    
    SysProc *SysProcCreate(const char *filepath, char **argv, char **envp) {
    #if defined(__APPLE__) || defined(__linux__)
        int stdin_pipe[2]  = {-1};
        close(stderr_pipe[WRITE_END]);
    
        SysProc *proc   = NEW(SysProc);
        proc->pid       = pid;
        proc->stdin_fd  = stdin_pipe[WRITE_END];
        CloseHandle(hStderrWrite); // parent won't write to child's stderr, will read from it
    
        SysProc *proc     = NEW(SysProc);
        proc->pi          = pi;
        proc->hStdinWrite = hStdinWrite;
    }
    
    void SysProcWait(SysProc *proc) {
        if (!proc) {
            LOG_FATAL("Invalid argument");
    }
    
    SysProcStatus SysProcWaitFor(SysProc *proc, u64 timeout_ms) {
        if (!proc) {
            LOG_FATAL("Invalid arguments");
    }
    
    void SysProcTerminate(SysProc *proc) {
        if (!proc) {
            LOG_FATAL("Invalid argument");
    
    
    void SysProcDestroy(SysProc *proc) {
        if (!proc) {
            LOG_FATAL("Invalid argument");
    }
    
    i32 SysProcWriteToStdin(SysProc *proc, Str *buf) {
        if (!proc || !buf) {
            LOG_FATAL("Invalid arguments");
    }
    
    i32 sys_proc_read_internal(SysProc *proc, Str *buf, bool is_stdout) {
        if (!proc || !buf) {
            LOG_FATAL("Invalid argument");
    }
    
    i32 SysProcReadFromStdout(SysProc *proc, Str *buf) {
        return sys_proc_read_internal(proc, buf, /* is stdout*/ true);
    }
    }
    
    i32 SysProcReadFromStderr(SysProc *proc, Str *buf) {
        return sys_proc_read_internal(proc, buf, /* is stdout*/ false);
    }
    }
    
    i32 SysProcGetId(SysProc *proc) {
        if (!proc) {
            LOG_FATAL("Invalid argument");
    }
    
    i32 SysProcIsRunning(SysProc *proc) {
        if (!proc) {
            LOG_FATAL("Invalid argument");
    }
    
    i32 SysProcGetExitCode(SysProc *proc) {
        if (!proc) {
            LOG_FATAL("Invalid argument");
    int main(int argc, char **argv, char **envp) {
        // create a new child process
        SysProc *proc = SysProcCreate(argv[1], argv + 1, envp);
    
        // write something to it's stdout
    /// FAILURE: NULL.
    ///
    SysProc *SysProcCreate(const char *path, char **argv, char **envp);
    
    ///
    /// FAILURE: Abort with log message.
    ///
    void SysProcWait(SysProc *proc);
    
    ///
    /// FAILURE: Abort with log message.
    ///
    SysProcStatus SysProcWaitFor(SysProc *proc, u64 timeout);
    
    ///
    /// FAILURE: Abort with log message.
    ///
    void SysProcTerminate(SysProc *proc);
    
    ///
    /// FAILURE: Abort with log message.
    ///
    void SysProcDestroy(SysProc *proc);
    
    ///
    /// FAILURE: Return -1
    ///
    i32 SysProcWriteToStdin(SysProc *proc, Str *buf);
    
    ///
    /// FAILURE: Abort with a log message.
    ///
    i32 SysProcGetExitCode(SysProc *proc);
    
    ///
    /// FAILURE: Return -1
    ///
    i32 SysProcReadFromStdout(SysProc *proc, Str *buf);
    
    ///
    /// FAILURE: Return -1
    ///
    i32 SysProcReadFromStderr(SysProc *proc, Str *buf);
    
    ///
    /// FAILURE: Returns -1
    ///
    i32 SysProcGetId(SysProc *proc);
    
    ///
    /// proc[in] : Child process handle.
    ///
    SysProcStatus SysProcGetStatus(SysProc *proc);
    
    ///
Last updated on