StopStrategy.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarXCore::core
19 * @author Cedric Seehausen
20 * @date 2016
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25
26#include "StopStrategy.h"
27
29
30#include "ProcessUtil.h"
31
32using namespace ScenarioManager;
33using namespace Exec;
34using namespace Data_Structure;
35
39
40void
41StopStrategy::awaitTermination(const ApplicationInstancePtr& application, int signalledPid)
42{
43 if (signalledPid <= 0)
44 {
45 return;
46 }
47
49 {
50 ARMARX_WARNING_S << "Application " << application->getName() << " (pid " << signalledPid
51 << ") did not terminate within " << TerminationTimeout.count()
52 << " ms. Giving up waiting for it; you may have to kill it manually.";
53 return;
54 }
55
56 // Only clear the pid if it is still the one we signalled: the application may have been
57 // started again while we were waiting.
58 if (application->compareAndResetPid(signalledPid))
59 {
60 StatusManager().savePid(application);
61 }
62}
void awaitTermination(const Data_Structure::ApplicationInstancePtr &application, int signalledPid)
Waits until the process that was signalled has terminated, then clears the application's pid.
static constexpr std::chrono::milliseconds TerminationTimeout
How long to wait for a signalled process to actually disappear before giving up.
StopStrategy(ApplicationStopperPtr stopper)
void savePid(Data_Structure::ApplicationInstancePtr app)
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:211
std::shared_ptr< ApplicationInstance > ApplicationInstancePtr
bool WaitForExit(int pid, std::chrono::milliseconds timeout, std::chrono::milliseconds pollInterval)
Blocks until the process with the given pid has disappeared, at most for timeout.
std::shared_ptr< ApplicationStopper > ApplicationStopperPtr