hello-world-cpp/task_3/process_launcher.h

34 lines
998 B
C
Raw Permalink Normal View History

2025-01-09 21:56:58 +10:00
#ifdef _WIN32
#include <windows.h>
#else
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#endif
#include <string>
class ProcessLauncher {
public:
// Запуск программы в фоновом режиме
static int launch(const std::string& command);
// Ожидание завершения процесса и получение его кода возврата
static int waitForProcess(int pid);
2025-01-10 14:44:36 +10:00
// проверка запущен ли процесс
static int isProcessActive(int pid);
2025-01-09 21:56:58 +10:00
private:
#ifdef _WIN32
// Для Windows
static int launchWindows(const std::string& command);
static int waitForProcessWindows(HANDLE processHandle);
2025-01-10 14:44:36 +10:00
static int isProcessActiveWindows(HANDLE processHandle);
2025-01-09 21:56:58 +10:00
#else
// Для UNIX-подобных систем
static int launchUnix(const std::string& command);
static int waitForProcessUnix(pid_t pid);
2025-01-10 14:44:36 +10:00
static int isProcessActiveUnix(pid_t pid);
2025-01-09 21:56:58 +10:00
#endif
2025-01-10 14:44:36 +10:00
};