У меня возникли проблемы с созданием последовательности независимых процессов в 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
Создание нового процесса в Linux [закрыто] ⇐ C++
Программы на C++. Форум разработчиков
-
Anonymous
1763381781
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
Подробнее здесь: [url]https://stackoverflow.com/questions/79822178/creating-new-process-on-linux[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия