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

📄 pcs_shutdown.c

📁 unix 下用pro*c tuxedo 开发的东西
💻 C
字号:
/*
*	File name		: Pcs_ShutDown.c
*	Purpose			: Terminate processes recorded in a certain file
which was created at startup time. 
*	Author			: Mr. Zhujingkun
*	Date Created	: 200004,01
*	Version			: Version 1.0
*	Environment		: HP UNIX
*	Portability		: UNIX Platform
*	Warnings		: no
*	Called Functions: When you want to close all the prcesses 
in a certain file.
*/

#include "stdlib.h"
#include "stdio.h"
#include "unistd.h"
#include "Pcs_ShutDown.h"

void main()
{
	char cProcessID[MAX_LINE_LEN+1];  //Not contain path information
	char cCommand[500], cDescription[500];
	FILE *hProcIDList;

	hProcIDList = fopen( STARTUP_PROCESS_ID_LIST, "r" );
	if( hProcIDList == NULL )
	{
		printf( "Pcs_ShutDown.x: Cannot open file: %s,The file may not exist!\n", STARTUP_PROCESS_LIST);
		exit(-1);
	}
	
	while( myapi_ReadALine( cProcessID, hProcIDList ) )
	{
		//Now I find a ProcessID
		sprintf( cCommand, "kill %s\n", cProcessID );
		system( cCommand );
		sprintf( cCommand, "kill -9 %s\n", cProcessID );
		system( cCommand );
	}
	fclose( hProcIDList );
	exit(0);
}

//
//Record the error message into errorlog file
//Need to truncate or delete as the size grow
//
void ErrorLog( const char* sErrorMessage )
{
	FILE* hErrorFile;
	char cDateTime[100];
	
	hErrorFile = fopen( ERROR_LOG_FILE, "a" );
	if( hErrorFile == NULL )
	{
		printf( "Critical! Cannot open ERROR_LOG_FILE for append or cannot create!\n");
		return;
	}
	fseek( hErrorFile, 0, SEEK_END );
	fputs( sErrorMessage, hErrorFile );
	fclose( hErrorFile );
	sprintf( cDateTime, "date >> %s\n", ERROR_LOG_FILE );
	system( cDateTime );
}


//
//Read a line to a string from a file, \n is excluded.
//return 1 if sucessful, 0 otherwise
//Do not close the file.
//
int myapi_ReadALine( char* cLine, FILE* hTable )
{
	char cChar;
	int i=0;
	cLine[0] = '\0';
	while( (cChar = fgetc( hTable )) != '\n' )
	{
		if( cChar == EOF ) return(0);
		cLine[i++] = cChar;
		
		//truncated if superlong
		if( i >= MAX_LINE_LEN ) i=0;
		cLine[i] = '\0';
	}
	return(1);
}

⌨️ 快捷键说明

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