Skip to content
Snippets Groups Projects
Commit f02333a5 authored by armatusmiles's avatar armatusmiles
Browse files

Add dap_process_manager

parent 149847b1
No related branches found
No related tags found
No related merge requests found
#ifdef __linux__
#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
#include "dap_process_manager.h"
#include "dap_common.h"
#undef LOG_TAG
#define LOG_TAG "dap_process_manager"
bool is_process_running(pid_t pid) {
return kill(pid, 0) == 0;
}
bool save_process_pid_in_file(const char* file_path) {
FILE * fpid = fopen(file_path, "w");
if (fpid == NULL) {
log_it(L_ERROR, "Cant create/open file by path %s",file_path);
return false;
}
fprintf(fpid, "%d", getpid());
fclose(fpid);
return true;
}
pid_t get_pid_from_file(const char* file_path) {
FILE * fpid = fopen(file_path, "r");
if (fpid == NULL) {
log_it(L_ERROR, "Cant create/open file by path %s",file_path);
return false;
}
pid_t f_pid = 0;
fscanf(fpid, "%d", &f_pid);
fclose(fpid);
return f_pid;
}
bool daemonize_process() {
return daemon(1,1) == 0;
}
bool kill_process(pid_t pid) {
if (!is_process_running(pid)) {
return false;
}
return kill(pid, SIGKILL) == 0;
}
#endif
#ifdef __linux__
#include <stdbool.h>
#include <unistd.h>
/* Saves process pid into file by file_path.
* If file exists he will be overwritten */
extern bool save_process_pid_in_file(const char* file_path);
/* File must consist only PID. Return 0 if file is clear. */
extern pid_t get_pid_from_file(const char* file_path);
/* Return true if process running */
extern bool is_process_running(pid_t pid);
/* Demonizes current process and exit from program */
extern bool daemonize_process(void);
/* Sends SIGKILL to process */
extern bool kill_process(pid_t pid);
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment