2024-06-02 20:03:02 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <sched.h>
|
|
|
|
#include <string>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/wait.h>
|
2024-06-05 14:18:45 +02:00
|
|
|
#include <vector>
|
2024-06-02 20:03:02 +02:00
|
|
|
|
|
|
|
#define SWAYBGPROCESS_BUFFER_SIZE 4094
|
|
|
|
|
2024-06-05 14:18:45 +02:00
|
|
|
class Process {
|
2024-06-02 20:03:02 +02:00
|
|
|
public:
|
|
|
|
|
2024-06-05 14:18:45 +02:00
|
|
|
Process(const std::string& execPath, const std::vector<const char*>& args);
|
2024-06-02 20:03:02 +02:00
|
|
|
|
2024-06-05 14:18:45 +02:00
|
|
|
~Process();
|
2024-06-02 20:03:02 +02:00
|
|
|
|
|
|
|
void exec();
|
|
|
|
|
|
|
|
void kill();
|
2024-06-05 14:18:45 +02:00
|
|
|
int wait();
|
2024-06-02 20:03:02 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2024-06-05 14:18:45 +02:00
|
|
|
std::string execPath;
|
|
|
|
std::vector<const char*> args;
|
2024-06-02 20:03:02 +02:00
|
|
|
pid_t pid;
|
|
|
|
bool killed = true;
|
|
|
|
|
|
|
|
int fds[2]; // file descriptors for pipe
|
|
|
|
char buf[SWAYBGPROCESS_BUFFER_SIZE];
|
|
|
|
ssize_t nbytes;
|
|
|
|
};
|
|
|
|
|