Class managing a subprocess.
More...
#include <Subprocess.h>
Classes | |
class | Handler |
Class used to cont/stop a Subprocess in an exception safe manner. More... | |
Public Member Functions | |
Subprocess (const std::string &cmd) | |
Constructor with a command line. More... | |
~Subprocess () | |
Destructor. More... | |
void | cont () noexcept |
Send a SIGCONT to the subprocess. More... | |
Handler | contStop () noexcept |
Returns a handler to temporarily resume the process. More... | |
void | flush () |
Flush communication to process. More... | |
Subprocess & | getline (std::string &) |
Get a line from the subprocess. More... | |
void | stop () noexcept |
Send a SIGSTOP to the subprocess. More... | |
Static Public Member Functions | |
static bool | available () noexcept |
Check if subprocess facilities are available. More... | |
Private Attributes | |
IFile | child_to_parent |
PLUMED file object, child to parent. More... | |
int | fcp =0 |
File descriptor, child to parent. More... | |
int | fpc =0 |
File descriptor, parent to child. More... | |
FILE * | fpcp =NULL |
File pointer, child to parent. More... | |
FILE * | fppc =NULL |
File pointer, parent to child. More... | |
OFile | parent_to_child |
PLUMED file object, parent to child. More... | |
std::unique_ptr< SubprocessPid > | pid |
Process ID. More... | |
Friends | |
template<class T > | |
Subprocess & | operator<< (Subprocess &ep, const T &t) |
Write something to the subprocess. More... | |
Class managing a subprocess.
The subprocess is launched and one can interact with it through a pipe.
In order not to consume resources, it might be possible to use this syntax:
// at construction: Subprocess sp; sp.stop(); // when needed { auto h=sp.contStop(); sp<<"command\n"; sp.flush(); sp.getline(answer); } // when h goes out of scope, subprocess is stopped again. // If an exception is raised in the block, the subprocess is stopped as well.
stop
and cont
are giving problems with some MPI implementation, In addition, notice that the stop signal is only sent to the child process and not to the subsequently spawn processes, so it might not work as intended. This feature is left here but is probably no a good idea to use it. It can be enabled with export PLUMED_ENABLE_SIGNALS=1
.
|
explicit |
Constructor with a command line.
PLMD::Subprocess::~Subprocess | ( | ) |
Destructor.
|
staticnoexcept |
Check if subprocess facilities are available.
If it returns false, any call to Subprocess constructor will raise an exception.
|
noexcept |
Send a SIGCONT to the subprocess.
Better used through contStop() method.
|
inlinenoexcept |
Returns a handler to temporarily resume the process.
void PLMD::Subprocess::flush | ( | ) |
Flush communication to process.
Subprocess & PLMD::Subprocess::getline | ( | std::string & | line | ) |
Get a line from the subprocess.
|
noexcept |
Send a SIGSTOP to the subprocess.
Better used through contStop() method.
|
friend |
Write something to the subprocess.
|
private |
PLUMED file object, child to parent.
Used to simplify formatting
|
private |
File descriptor, child to parent.
|
private |
File descriptor, parent to child.
|
private |
File pointer, child to parent.
|
private |
File pointer, parent to child.
|
private |
PLUMED file object, parent to child.
Used to simplify formatting
|
private |
Process ID.
We store this rather than pid_t to avoid including <unistd.h> in this header file. This remains nullptr in the child process.
Hosted by GitHub | 1.8.14 |