Создание нового процесса в Linux [закрыто]C++

Программы на C++. Форум разработчиков
Anonymous
Создание нового процесса в Linux [закрыто]

Сообщение Anonymous »

У меня возникли проблемы с созданием последовательности независимых процессов в Linux.
Вот что я делаю:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

using namespace std::chrono_literals;
extern char **environ;

pid_t LaunchNewConsole( const std::string& cmd, const std::string& title ) {
const char* term_exe = "xterm";

std::vector args;
args.push_back(term_exe);
args.push_back("-title");
args.push_back(title);
args.push_back("-e");
args.push_back("/bin/sh");
args.push_back("-c");

args.push_back("exec " + cmd);

std::vector argv_c;
for (const std::string& s : args) {
argv_c.push_back(s.c_str());
}
argv_c.push_back(nullptr);

pid_t pid = -1;

int ret = posix_spawnp(
&pid,
term_exe,
nullptr,
nullptr,
const_cast(argv_c.data()),
environ
);

if (ret!= 0) {
throw std::system_error(ret, std::system_category(), "posix_spawnp failed for xterm");
}

return pid;
}

int main() {
std::vector< pid_t > processes;
const auto cmd = std::filesystem::current_path().string() + "/simple";
std::vector< std::pair> cmd_and_title;
for (auto i{0}; i < 6; ++i) {
cmd_and_title.push_back({cmd, "p_" + std::to_string(i)});
}
for (const auto& [cmd, title]: cmd_and_title) {
std::cout

Подробнее здесь: https://stackoverflow.com/questions/798 ... s-on-linux

Вернуться в «C++»