mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Interprocess Communication

Tools for managing interprocess communication (IPC)

Modules

 Message Queues
 
 Shared Memory
 

Files

file  processInterface.hpp
 Process interface facilities.
 
file  sharedMemSegment.hpp
 Declarations for the mxlib shared memory facility.
 
file  processInterface.cpp
 Process interface facilities.
 
file  sharedMemSegment.cpp
 Definitions for the mxlib shared memory facility.
 

Functions

int mx::ipc::command_response (const char *cmd, char *resp, size_t respsz)
 Run a process and copy the output to a string. More...
 
int mx::ipc::runCommand (int &retVal, std::vector< std::string > &commandOutput, std::vector< std::string > &commandStderr, const std::vector< std::string > &commandList)
 Runs a command (with parameters) passed in using fork/exec. More...
 

Function Documentation

◆ command_response()

int mx::ipc::command_response ( const char *  cmd,
char *  resp,
size_t  respsz 
)

Run a process and copy the output to a string.

Uses popen, so the attendant precautions about privileges apply.

Parameters
cmdis the command to run
respis the string to copy the response to.
respszis the available size of the string.
Return values
0on success
-1on error

Definition at line 43 of file processInterface.cpp.

◆ runCommand()

int mx::ipc::runCommand ( int &  retVal,
std::vector< std::string > &  commandOutput,
std::vector< std::string > &  commandStderr,
const std::vector< std::string > &  commandList 
)

Runs a command (with parameters) passed in using fork/exec.

A new process is fork()-ed, and the child runs execvp with command provided. The output of the process is captured in commandOutput, and error messages in commandStderr.

The process return value in retVal is only meaningful if this function returns 0.

If this function returns -1, the last entry in commandStderr will contain a message, and errno may be useful.

Returns
0 on success
-1 on error
Parameters
[out]retValthe return value of the process. Only meaningful if this returns 0.
[out]commandOutputthe output, line by line. If an error, first entry contains the message.
[out]commandStderrthe output of stderr.
[in]commandListcommand to be run, with one entry per command line word

Definition at line 71 of file processInterface.cpp.

Referenced by mx::sys::gitRepo::getGitFileState(), mx::sys::gitRepo::getGitHash(), mx::sys::gitRepo::getGitModified(), and mx::sys::gitRepo::getGitName().