libfastcommon/src/process_ctrl.h

64 lines
1.7 KiB
C

/*
* Copyright (c) 2020 YuQing <384681@qq.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the Lesser GNU General Public License, version 3
* or later ("LGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the Lesser GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef PROCESS_CTRL_H
#define PROCESS_CTRL_H
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#ifdef __cplusplus
extern "C" {
#endif
int get_base_path_from_conf_file_ex(const char *filename, char *base_path,
const int path_size, const int noent_log_level);
#define get_base_path_from_conf_file(filename, base_path, path_size) \
get_base_path_from_conf_file_ex(filename, base_path, path_size, LOG_ERR)
int get_pid_from_file(const char *pidFilename, pid_t *pid);
int write_to_pid_file(const char *pidFilename);
int delete_pid_file(const char *pidFilename);
int process_stop_ex(const char *pidFilename,
const bool bShowError, bool *force);
static inline int process_stop(const char *pidFilename)
{
const bool bShowError = true;
bool force;
return process_stop_ex(pidFilename, bShowError, &force);
}
int process_restart(const char *pidFilename);
int process_exist(const char *pidFilename, pid_t *pid);
int process_action(const char *pidFilename, const char *action, bool *stop);
#ifdef __cplusplus
}
#endif
#endif