ÀÚµ¿À¸·Î ƯÁ¤ ÇÁ·Î¼¼½º µÇ»ì¸®±â |
±Û ¾´ ÀÌ |
linux |
³¯ Â¥ |
2003³â 01¿ù 17ÀÏ 23½Ã 35ºÐ 49ÃÊ |
º» ¹® |
¼¹ö °ü¸® ÆíÀÇ»ó ¸¸µé¾îµÐ ¸î¸î ÇÁ·Î¼¼½ºµéÀÌ ÀÌÀ¯¾øÀÌ Áױ淡...
¾ÈÁ×À»¶§±îÁö µð¹ö±ëÇϴ°ͺ¸´Ù ±×³É ´Ù½Ã ¶ç¿ì´Â°Ô ³ªÀ»µíÇؼ (¾Æ~~ °ÔÀ¸¸§...)
¶Òµü ¸¸µé¾îºÃ½À´Ï´Ù.
[ÄÄÆÄÀÏ]
define µÈ EXEC_NAME °ú LOG_FILEÀ» Àû´çÈ÷ ¼öÁ¤ÇÑ ÈÄ
gcc -o snakeye snakeye.c ȤÀº make snakeye
[½ÇÇà]
./snakeye
±×¸®°í, °¡²û »ý°¢³ª¸é ·Î±×È®ÀÎ.
ÀÌ ³à¼® ¶Ç ¸î¹øÀ̳ª Á×¾ú´Ù »ì¾Æ³µ±¸¸¸...-_-;
±×¸®°í, »ç¿ë, ¼öÁ¤, Àç¹èÆ÷´Â ¸¶À½´ë·Î~~~
/**********************************************************
½º³×ÀÌÅ©¾ÆÀÌ.... ^^
snakeye.c v0.1
ƯÁ¤ ÇÁ·Î¼¼½ºÀÇ È°µ¿À» üũ.....
Á×À¸¸é ´Ù½Ã »ì¸°´Ù... ^^
2001.6.01 Khan ZieNie (zienie@hanmir.com)
**********************************************************/
#include
#include
#include
#include
#define WAIT_TIME 60 /* °Ë»çÇÏ´Â °£°Ý (ÃÊ) */
#define EXEC_NAME "/home/zienie/some_program" /* ½ÇÇàÇÒ ÇÁ·Î±×·¥ */
#define LOG_FILE "/home/zienie/log/snakeye.log" /* ·Î±×ÆÄÀÏ */
int load_ps ();
int make_log ();
main ( void )
{
int c_pid, stat;
if ( fork () )
{
printf ( "\n=====================================================================" );
printf ( "\n S T A R T snakeye v0.1 by ZieNie" );
printf ( "\n=====================================================================" );
printf ( "\n watching....[%s]\n", EXEC_NAME );
exit ( 1 );
}
c_pid = load_ps ( 0 );
while ( 1 )
{
if ( waitpid ( c_pid, &stat, WNOHANG ) != 0 )
c_pid = load_ps ( 1 );
sleep ( WAIT_TIME );
}
}
/***** ÇÁ·Î±×·¥ ·Îµå ********/
int load_ps ( int method )
{
int c_pid;
char str[256];
c_pid = fork ();
if ( c_pid == 0 )
{
execl ( EXEC_NAME, (char *)0 );
exit ( 1 );
}
if ( method == 0 ) /* óÀ½ ±¸µ¿½Ã ·Î±×. */
{
make_log ( "=====================================================================" );
make_log ( " S T A R T snakeye v0.1 by ZieNie" );
make_log ( "=====================================================================" );
sprintf ( str, "Loading...[%s]: PID:%d", EXEC_NAME, c_pid );
}
else /* ¸®·Îµå½Ã ·Î±× */
sprintf ( str, "Reloaing...[%s]: PID:%d", EXEC_NAME, c_pid );
make_log ( str );
return c_pid;
}
/* ¸Þ¼¼Áö¸¦ ¹Þ¾Æ¼ ·Î±×ÆÄÀÏÀ» ¸¸µç´Ù. */
int make_log ( char *msg )
{
time_t t;
struct tm *get;
FILE *fp;
fp = fopen ( LOG_FILE, "a" );
if ( fp == NULL )
return ( 0 ); /* ·Î±×¸¦ ¸ø¸¸µé¸é ±×³É ¸®ÅÏ.... */
t = time ( 0 );
get = localtime ( &t );
fprintf ( fp, "[%02d/%02d %02d:%02d:%02d] %s\n",
get->tm_mon+1, get->tm_mday, get->tm_hour, get->tm_min, get->tm_sec, msg );
fclose ( fp );
} |
|
|
|