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. | |
| ~Subprocess () | |
| Destructor. | |
| void | cont () noexcept |
| Send a SIGCONT to the subprocess. | |
| Handler | contStop () noexcept |
| Returns a handler to temporarily resume the process. | |
| void | flush () |
| Flush communication to process. | |
| Subprocess & | getline (std::string &) |
| Get a line from the subprocess. | |
| void | stop () noexcept |
| Send a SIGSTOP to the subprocess. | |
Static Public Member Functions | |
| static bool | available () noexcept |
| Check if subprocess facilities are available. | |
Private Attributes | |
| IFile | child_to_parent |
| PLUMED file object, child to parent. | |
| int | fcp =0 |
| File descriptor, child to parent. | |
| int | fpc =0 |
| File descriptor, parent to child. | |
| FILE * | fpcp =NULL |
| File pointer, child to parent. | |
| FILE * | fppc =NULL |
| File pointer, parent to child. | |
| OFile | parent_to_child |
| PLUMED file object, parent to child. | |
| std::unique_ptr< SubprocessPid > | pid |
| Process ID. | |
Friends | |
| template<class T> | |
| Subprocess & | operator<< (Subprocess &ep, const T &t) |
| Write something to the subprocess. | |
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.
|
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.17.0
|