YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Run.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef YARP_RUN_RUN_H
8#define YARP_RUN_RUN_H
9
10#include <vector>
11
12#include <cstring>
13#include <yarp/run/api.h>
14#include <yarp/os/RpcServer.h>
15#include <yarp/os/Property.h>
17
18
21
22
23/*
24 * Typical YARP applications consist of several intercommunicating modules distributed on different machines.
25 * If a yarprun server is running on each machine, distributed applications can be remotely launched,
26 * monitored and terminated by yarprun commands.
27 *
28 * - To run a yarprun server on a machine:
29 * $ yarprun --server /SERVERPORT
30 *
31 * /SERVERPORT must be unique and identifies the remote machine.
32 *
33 * - The basic command to run a command/application on a remote machine is:
34 * $ yarprun --on /SERVERPORT --as TAG --cmd COMMAND [ARGLIST]
35 *
36 * /SERVERPORT is the name of the server that actually runs the command
37 * TAG identifies the application process set, and must be unique
38 * COMMAND is the application that has to be executed, followed by the optional argument list
39 *
40 * Some options can be added to the basic format of yarprun:
41 * $ yarprun --on /SERVERPORT1 --as TAG --cmd COMMAND [ARGLIST] --stdio /SERVERPORT2
42 *
43 * opens a remote shell window where the stdin, stdout and stderr of the application will be redirected.
44 * /SERVERPORT2 specifies the machine where the IO shell will be executed, and can be either a remote machine or
45 * be equal to /SERVERPORT1 itself.
46 *
47 * If --stdio is specified, there are two useful sub-options (linux only):
48 * - --hold keep the stdio window open even if the command is terminated or aborted.
49 * - --geometry WxH+X+Y set the stdio window size and position. Example: --geometry 320x240+80+20
50 *
51 * Other yarprun commands:
52 *
53 * - To terminate an application, the yarprun syntax is:
54 * $ yarprun --on /SERVERPORT --sigterm TAG
55 *
56 * - To send a signal to an application (usually SIGKILL) use:
57 * $ yarprun --on /SERVERPORT --kill TAG SIGNUM
58 *
59 * - To terminate all the applications managed by a yarprun server, use:
60 * $ yarprun --on /SERVERPORT --sigtermall
61 *
62 * - To check if an application is still running on a yarprun server, use:
63 * $ yarprun --on /SERVERPORT --isrunning TAG
64 *
65 * - To get a report of applications running on a yarprun server, use:
66 * $ yarprun --on /SERVERPORT --ps
67 *
68 * - To shutdown a yarprun server, use:
69 * $ yarprun --on /SERVERPORT --exit
70 *
71 */
72
73namespace yarp::run {
74
81{
82public:
83 // API
85 {
86 int pid=0;
87 std::string tag;
88 std::string status;
89 std::string command;
90 std::string env;
91 };
92
106 static bool start(const std::string &node, yarp::os::Property &command, std::string &keyv);
107
114 static bool sigterm(const std::string &node, const std::string &keyv);
115
121 static bool sigtermall(const std::string &node);
122
130 static bool kill(const std::string &node, const std::string &keyv, int s);
131
138 static bool ps(const std::string &node, std::vector<processInfo>& processes);
139
146 static bool sysinfo(const std::string& node, yarp::os::SystemInfoSerializer& info);
147
148
155 static bool isRunning(const std::string &node, const std::string &keyv);
156
163 static bool which(const std::string &node, const std::string &keyv);
164
170 static bool exit(const std::string& node);
171
172 // end API
173
185 static int client(yarp::os::Property& config);
186
187#ifndef DOXYGEN_SHOULD_SKIP_THIS
188
189 static int main(int argc, char *argv[]);
190 static yarp::os::RpcServer *pServerPort;
191
192 static bool mStresstest;
193
194 static bool mLogged;
197 static std::string mLoggerPort;
198
199#if defined(_WIN32)
200 static YarpRunInfoVector mProcessVector;
201 static YarpRunInfoVector mStdioVector;
202#else
203 static YarpRunInfoVector *mProcessVector;
204 static YarpRunInfoVector *mStdioVector;
205 static ZombieHunterThread *mBraveZombieHunter;
206 static void CleanZombie(int pid);
207#define READ_FROM_PIPE 0
208#define WRITE_TO_PIPE 1
209#define REDIRECT_TO(from, to) yarp::run::impl::dup2(to, from)
210#endif
212 static yarp::os::Bottle sendMsg(yarp::os::Bottle& msg, std::string target, int RETRY=20, double DELAY=0.5);
213
214protected:
215 static void Help(const char* msg="");
216 static int server();
217 static int executeCmdAndStdio(const yarp::os::Bottle& msg, yarp::os::Bottle& result);
218 static int executeCmdStdout(const yarp::os::Bottle& msg, yarp::os::Bottle& result, std::string& loggerName);
219 static int executeCmd(const yarp::os::Bottle& msg, yarp::os::Bottle& result);
220 static int userStdio(const yarp::os::Bottle& msg, yarp::os::Bottle& result);
221
222 static inline bool IS_PARENT_OF(int pid){ return pid>0; }
223 static inline bool IS_NEW_PROCESS(int pid){ return !pid; }
224 static inline bool IS_INVALID(int pid){ return pid<0; }
225
227 static std::string mPortName;
228 static int mProcCNT;
229
230#if !defined(_WIN32)
231 static void cleanBeforeExec();
232 static void writeToPipe(int fd, std::string str);
233 static int readFromPipe(int fd, char* &data, int& buffsize);
234#endif
235
236 static void cmdcpy(char* &dst, const char* src)
237 {
238 dst=new char[(strlen(src)/8+2)*16];
239 strcpy(dst, src);
240 }
241
242 static void cmdclean(char **cmd)
243 {
244 while (*cmd)
245 {
246 delete [] *cmd++;
247 }
248 }
249
250#endif /*DOXYGEN_SHOULD_SKIP_THIS*/
251};
252
253} // namespace yarp::run
254
255
256#endif // YARP_RUN_RUN_H
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:65
A class for storing options and configuration information.
Definition Property.h:33
A port that is specialized as an RPC server.
Definition RpcServer.h:23
A helper class to pass the SystemInfo object around the YARP network.
int main(int argc, char *argv[])
Definition main.cpp:121
std::string command
Definition Run.h:89
std::string status
Definition Run.h:88
#define YARP_DISABLE_DLL_INTERFACE_WARNING
Disable MSVC C4251 warnings in the following code.
Definition system.h:336
#define YARP_WARNING_POP
Ends a temporary alteration of the enabled warnings.
Definition system.h:334
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING
Suppress MSVC C4251 warning for the next line.
Definition system.h:337
#define YARP_WARNING_PUSH
Starts a temporary alteration of the enabled warnings.
Definition system.h:333
#define YARP_run_API
Definition api.h:17