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 <cstring>
11#include <yarp/run/api.h>
12#include <yarp/os/RpcServer.h>
13#include <yarp/os/Property.h>
14
15
18
19
20/*
21 * Typical YARP applications consist of several intercommunicating modules distributed on different machines.
22 * If a yarprun server is running on each machine, distributed applications can be remotely launched,
23 * monitored and terminated by yarprun commands.
24 *
25 * - To run a yarprun server on a machine:
26 * $ yarprun --server /SERVERPORT
27 *
28 * /SERVERPORT must be unique and identifies the remote machine.
29 *
30 * - The basic command to run a command/application on a remote machine is:
31 * $ yarprun --on /SERVERPORT --as TAG --cmd COMMAND [ARGLIST]
32 *
33 * /SERVERPORT is the name of the server that actually runs the command
34 * TAG identifies the application process set, and must be unique
35 * COMMAND is the application that has to be executed, followed by the optional argument list
36 *
37 * Some options can be added to the basic format of yarprun:
38 * $ yarprun --on /SERVERPORT1 --as TAG --cmd COMMAND [ARGLIST] --stdio /SERVERPORT2
39 *
40 * opens a remote shell window where the stdin, stdout and stderr of the application will be redirected.
41 * /SERVERPORT2 specifies the machine where the IO shell will be executed, and can be either a remote machine or
42 * be equal to /SERVERPORT1 itself.
43 *
44 * If --stdio is specified, there are two useful sub-options (linux only):
45 * - --hold keep the stdio window open even if the command is terminated or aborted.
46 * - --geometry WxH+X+Y set the stdio window size and position. Example: --geometry 320x240+80+20
47 *
48 * Other yarprun commands:
49 *
50 * - To terminate an application, the yarprun syntax is:
51 * $ yarprun --on /SERVERPORT --sigterm TAG
52 *
53 * - To send a signal to an application (usually SIGKILL) use:
54 * $ yarprun --on /SERVERPORT --kill TAG SIGNUM
55 *
56 * - To terminate all the applications managed by a yarprun server, use:
57 * $ yarprun --on /SERVERPORT --sigtermall
58 *
59 * - To check if an application is still running on a yarprun server, use:
60 * $ yarprun --on /SERVERPORT --isrunning TAG
61 *
62 * - To get a report of applications running on a yarprun server, use:
63 * $ yarprun --on /SERVERPORT --ps
64 *
65 * - To shutdown a yarprun server, use:
66 * $ yarprun --on /SERVERPORT --exit
67 *
68 */
69
70namespace yarp::run {
71
78{
79public:
80 // API
81
95 static int start(const std::string &node, yarp::os::Property &command, std::string &keyv);
102 static int sigterm(const std::string &node, const std::string &keyv);
108 static int sigterm(const std::string &node);
116 static int kill(const std::string &node, const std::string &keyv, int s);
125 // static int ps(const std::string &node, std::string** &processes, int &num_processes);
132 static bool isRunning(const std::string &node, std::string &keyv);
133
134 // end API
135
147 static int client(yarp::os::Property& config);
148
149#ifndef DOXYGEN_SHOULD_SKIP_THIS
150
151 static int main(int argc, char *argv[]);
152 static yarp::os::RpcServer *pServerPort;
153
154 static bool mStresstest;
155
156 static bool mLogged;
159 static std::string mLoggerPort;
160
161#if defined(_WIN32)
162 static YarpRunInfoVector mProcessVector;
163 static YarpRunInfoVector mStdioVector;
164#else
165 static YarpRunInfoVector *mProcessVector;
166 static YarpRunInfoVector *mStdioVector;
167 static ZombieHunterThread *mBraveZombieHunter;
168 static void CleanZombie(int pid);
169#endif
171 static yarp::os::Bottle sendMsg(yarp::os::Bottle& msg, std::string target, int RETRY=20, double DELAY=0.5);
172
173protected:
174 static void Help(const char* msg="");
175 static int server();
176 static int executeCmdAndStdio(yarp::os::Bottle& msg, yarp::os::Bottle& result);
177 static int executeCmdStdout(yarp::os::Bottle& msg, yarp::os::Bottle& result, std::string& loggerName);
178 static int executeCmd(yarp::os::Bottle& msg, yarp::os::Bottle& result);
179 static int userStdio(yarp::os::Bottle& msg, yarp::os::Bottle& result);
180
181 static inline bool IS_PARENT_OF(int pid){ return pid>0; }
182 static inline bool IS_NEW_PROCESS(int pid){ return !pid; }
183 static inline bool IS_INVALID(int pid){ return pid<0; }
184
186 static std::string mPortName;
187 static int mProcCNT;
188
189#if !defined(_WIN32)
190 static void cleanBeforeExec();
191 static void writeToPipe(int fd, std::string str);
192 static int readFromPipe(int fd, char* &data, int& buffsize);
193#endif
194
195 static void cmdcpy(char* &dst, const char* src)
196 {
197 dst=new char[(strlen(src)/8+2)*16];
198 strcpy(dst, src);
199 }
200
201 static void cmdclean(char **cmd)
202 {
203 while (*cmd)
204 {
205 delete [] *cmd++;
206 }
207 }
208
209#endif /*DOXYGEN_SHOULD_SKIP_THIS*/
210};
211
212} // namespace yarp::run
213
214
215#endif // YARP_RUN_RUN_H
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
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
int main(int argc, char *argv[])
Definition main.cpp:121
#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