Skip to content

Commit

Permalink
[service]: fix launching and terminating deteched process
Browse files Browse the repository at this point in the history
  • Loading branch information
Robotics010 committed Sep 23, 2023
1 parent 2fc239e commit b168c83
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 9 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Typically a software team has a production code to be tested; a simulation tool

Current project is under active development and is not ready yet to be in use.

Help wanted:
* Windows integration
* Cmake review

## Notes

### service notes
Expand All @@ -20,6 +24,13 @@ Current project is under active development and is not ready yet to be in use.
~/cycle_on/service$ ./build/src/service
```

### service integration

```
~/cycle_on/$ sudo bash docker/installers/install_essentials.sh
~/cycle_on/$ sudo bash docker/installers/install_boost.sh
```

### cli-tool notes
```
$ python3 -m pip install build
Expand Down
13 changes: 6 additions & 7 deletions cli_tool/data/global_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
"port": 8181
},
"action": {
"modules": [
"modules": [],
"simulators": [
{
"command": "touch",
"command": "/home/robo/CARLA_0.9.12/CarlaUE4.sh",
"parameters": [
"/cycleon/service",
"temp_file_to_check_child_runner.dat"
"-prefernvidia",
"-carla-rpc-port=3000",
"-quality-level=Low"
]
}
],
"simulators": [

]
}
}
1 change: 1 addition & 0 deletions service/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)
find_package(Threads REQUIRED)
find_package(Boost REQUIRED COMPONENTS
filesystem)

Expand Down
11 changes: 9 additions & 2 deletions service/src/runner/child.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ using namespace cycleon::runner;
Child::Child(const std::vector<std::string>& arguments)
: arguments_(arguments) {}

void Child::Open() { child_.reset(new bp::child(bp::args(arguments_))); }
void Child::Open() {
child_.reset(new bp::child(bp::args(arguments_), group_));
// std::cout << "Child: id " << child_->id() << std::endl;
}

void Child::Close() { child_->terminate(); }
void Child::Close() {
group_.terminate();
child_->wait();
// std::cout << "Child: exit_code " << child_->exit_code() << std::endl;
}
2 changes: 2 additions & 0 deletions service/src/runner/child.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define RUNNER_CHILD_H_

#include <boost/process/child.hpp>
#include <boost/process/group.hpp>
#include <memory>

#include "runner/module.hpp"
Expand All @@ -20,6 +21,7 @@ class Child final : public ModuleBase {

private:
childPtr child_;
bp::group group_;
std::vector<std::string> arguments_;
};

Expand Down
1 change: 1 addition & 0 deletions service/src/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ target_link_libraries(
tcp_server
handler
nlohmann_json::nlohmann_json
Threads::Threads
)

target_include_directories(
Expand Down

0 comments on commit b168c83

Please sign in to comment.