Guo Wenxue
2019-06-26 d5ad51c46446e261d964515ca3a6bddb8559e014
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/********************************************************************************
 *      Copyright:  (C) 2018 LingYun IoT System Studio
 *                  All rights reserved.
 *
 *       Filename:  proc.h
 *    Description:  This head file is for Linux process API
 *
 *        Version:  1.0.0(11/06/2018~)
 *         Author:  Guo Wenxue <guowenxue@gmail.com>
 *      ChangeLog:  1, Release initial version on "11/06/2018 09:21:33 PM"
 *                 
 ********************************************************************************/
 
#ifndef __CP_PROC_H
#define __CP_PROC_H
 
#include <signal.h>
 
#define PID_ASCII_SIZE  11
 
typedef struct _st_sigproc
{
    int       signal;
    unsigned  stop;     /* 0: Not term  1: Stop  */
}  st_sigproc;
 
 
/* global variable for process or thread to exit  */
extern st_sigproc     g_signal;
 
/* install signal handler  */
extern void install_proc_signal(void);
 
/* record process PID into $pid_file for check_daemon_running() to check program running or not */
extern int record_daemon_pid(const char *pid_file);
 
/* check program already running or not  
 * 1: The daemon program alread running   0: Not running
 */
extern int check_daemon_running(const char *pid_file);
 
/* set program running as daemon */
extern int set_daemon_running(const char *pid_file);
 
/* create a system command and excute it */
extern void exec_system_cmd(const char *format, ...);
 
/* create and start a thread to excute function pointed by $thread_workbody  */
typedef void *(thread_function) (void *thread_arg);
extern int thread_start(pthread_t * thread_id, thread_function * thread_workbody, void *thread_arg);
 
#endif