⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 public.h

📁 UNIX环境下资源监控程序(包含对CPUMEMDISKIOPS等资源的监控)
💻 H
字号:
/********************************************************************/
/*	File Name		: public.h										*/
/*	Description		: The header file of the program public.c		*/
/*	Progrmmer:		: public										*/
/*	Last Update		:            									*/
/*	Program Language: ANSI C										*/
/*	compiler		: 	cc											*/
/*	Modify History	:												*/
/*		Programmer	:												*/
/*		Date		:												*/
/*		Amendments	:												*/
/********************************************************************/
#ifndef _H_PUBLIC_
#define _H_PUBLIC_

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/types.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <time.h>
#include <sys/sem.h>
#include <sys/ipc.h>
#include <signal.h>
#include <sys/select.h>
/* #include <sys/itimer.h> */
#include <fcntl.h>

/******************The constants Defined By lht**********************/

#define ASCEND  1					/*ascend*/
#define DESCEND 2					/*descend*/
#define LOCALDATE ".LOCALDATE.INI"	/*localdate file*/

#ifndef LEN
#define LEN 512
#endif		/*LEN*/

#ifndef TESTCOUNT
#define	TESTCOUNT 5
#endif

#ifndef SENDCOUNT
#define	SENDCOUNT 5
#endif

#ifndef CPUWARN
#define CPUWARN	 100
#endif

#ifndef MEMWARN
#define MEMWARN	0 
#endif

#ifndef DSKWARN
#define DSKWARN	0 
#endif

#define	LONG_STRING_SIZE	1000			/*用于定义长字串数组*/
#define NORMAL_STRING_SIZE	100				/*用于定义一般字串数组*/
#define	SHORT_STRING_SIZE	30				/*用于定义短的字串数组*/
#define	SEM_KEY				0x200

union semun									/*信号量联合体*/
{
	int		 val;
	struct   semid_ds *buf;
	unsigned short *array;
};


typedef struct
{
	int		sem_id;							/*信号量标识*/
	key_t	semkey;								/*信号量的key值*/
} STRU_PARAM;

STRU_PARAM gs_param;						/*公共参数变量*/

typedef struct h_file_struct
{
	pid_t	pid;
	char	filename[30];
}FILESTRUCT;

/******************Declare The Subprograme**************************/

/*get rid of blanks at the head of the acz_string or at the end of it */				
char *prune(const char *acp_string);
	
/*find the index of the find_char refer to in the string acz_string*/
int find_index(	const char *acp_string,/*string in locate char*/
				char 	ac_char			/*the char will be located*/
			  );
			  
/*function read para from parameter file*/

int	read_parafile(	FILE*	ah_file,
					char*	acz_servaddr,
					char*	acz_port,
					char*	acz_interval,
					char*	acz_unusualfile,
					char*	acz_lckfile);

int read_para_file(	FILE*	ah_file,
				char	acza_port[][LEN],
				int*	ai_port,
				char	acza_processes[][LEN],
				int*	ai_process,
				int*	ai_terval,
				char*	acz_unusualfile,
				char*	acz_lckfile
			 );

int	get_para_info(	FILE*	ah_file,
					char*	acz_paratype,	\
					char*	acz_para,	\
					char*	acz_value	\
				);

int	get_para_array(	int*	api_error,	
					FILE*	ah_file,
					char*	acz_paratype,	\
					char*	acz_para,	\
					char	acz_value[][LEN]	\
				);

int OpenSemSet(key_t key,int sem_count);

int SetSemVal(int ai_sid,int ai_sem_index,int ai_value);

int GetSemVal(int ai_sid,int ai_sem_index);

int	f_lock(char* acz_lckfile);

int f_unlock(char*	acz_lckfile);

int	write_unusuality(	char * acz_unusualfile,
						char* acz_lckfile,
						char * acz_string,
						int ai_len
					);

void error_deal(int	ai_error_type);
void WriteLogFile(char * str);
void CloseFile(FILE * fp);
FILE * OpenFile(char * file_name,FILE * fp,char * opentype);

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -