Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

LINUXÊØ»¤½ø³Ì


int Daemon(char* szExecName = NULL)
{
 int res = 0;
 pid_t pc;
 pc = fork();
 if(pc < 0)
 {
  fprintf(stderr,"ERROR_Deamon()_fork(): failed!");
  return -1;
 }
 else if(pc == 0) //sub process
 {
 }
 else if(pc > 0)  //parent process
 {
  fprintf(stderr,"parent process exit!\n");
  sleep(2);
  exit(0);
 }
 res = setsid();
 if(res == -1)
 {
  fprintf(stderr,"ERROR_Deamon()_setsid(): errno = %d\n", errno);
  return -1;
 }
 if(pc=fork())
  exit(0);//ÊǵÚÒ»×Ó½ø³Ì£¬½áÊøµÚÒ»×Ó½ø³Ì
 else if(pc< 0)
  exit(1);//forkʧ°Ü£¬Í˳ö
 //Êǵڶþ×Ó½ø³Ì£¬¼ÌÐø
 //µÚ¶þ×Ó½ø³Ì²»ÔÙÊǻỰ×鳤
 // for maybe its path is not current path when run.
 char szModulePath[MAX_PATH] = {0};
 GetModuleFileName(szExecName, szModulePath, sizeof(szModulePath));
 res = chdir(szModulePath);
 if(res == -1)
 {
  fprintf(stderr,"ERROR_Deamon()_chdir(): path = %s, errno = %d\n", szModulePath, errno);
  return -1;
 }
 umask(0);
 //for(int i = 0; i < MAXFILE; i++)
// {
  //close(i);
 //}
 return 0;
}Dstlen)
  *szTmp = '\0';
 return i;
}
1.»ñÈ¡³ÌÐòÔËÐеľø¶Ô·¾¶
int GetModuleFileName(char* sModuleName, char* sModulePath, int nSize)
{
 int ret = -1;
 char* p = getenv("_");
 if(p != NULL && strstr(p, sModuleName) != NULL)
 {
  realpath(p, sModulePath);
  char* p = strrchr(sModulePath, '/');
  p[1] = '\0';
  ret = 0;
 }
 else
 {
  realpath(sModuleName, sModulePath);
  char* p = strrchr(sModuleP/');
  p[1] = '\0';
  ret = 0;
 }
 return ret;
}


Ïà¹ØÎĵµ£º

LinuxѧϰÔÓ¼Ç

1. find ÔÚÌض¨µÄĿ¼ÏÂËÑË÷²¢ÏÔʾָ¶¨Ãû³ÆµÄÎļþºÍĿ¼
     ËÑË÷Ò»¶Îʱ¼äÄÚ±»´æÈ¡/±ä¸üµÄÎļþ»òĿ¼
find /home -admin -10 Ê®·ÖÖÓÄÚ´æÈ¡µÄÎļþ»òĿ¼
find /home -atime -10 Ê®¸öСʱÄÚ´æÈ¡µÄÎļþ»òĿ¼
find /home -cmin  -10 Ê®·ÖÖÓÄÚ¸ü¸Ä¹ýµÄÎļþ»òĿ¼
find /home -ctime +10 Ê®Ð¡Ê±Ç ......

linuxÏÂÍøÂçÁ÷Á¿¼à¿Ø¹¤¾ß

²âÁ¿Íø¿¨µÄÍøÂçÁ÷Á¿£¬linuxÏÂÓÐÁ½¿îС¹¤¾ßnloadºÍiftop
ÏÂÔØÔ´Îļþºóconfigue && make && make install
¸öÈ˱ȽÏϲ»¶iftop£¬ËüÄܶ¯Ì¬µÄÓüòµ¥µÄASCͼ±êʶÍø¿¨µ±Ç°Á÷Á¿
Ê×ÐÐÊÇÍøÂçÁ÷Á¿¿Ì¶È£¬
ÖмäÊÇÓëÆäËü»úÆ÷µÄÁ÷Á¿£¬Óиö°×µ×µÄbarÖ±¹ÛµÄ±êʶÁ÷Á¿±ä»¯£¬ºóÈýÁÐÊý¾Ý·Ö±ð±íʾ£º
1. preceding 2 seco ......

linuxÖ®cp/scpÃüÁscpÃüÁîÏê½â

Ãû³Æ£ºcp
ʹÓÃȨÏÞ£ºËùÓÐʹÓÃÕß
ʹÓ÷½Ê½£º
cp [options] source dest
cp [options] source... directory
˵Ã÷£º½«Ò»¸öµµ°¸¿½±´ÖÁÁíÒ»µµ°¸£¬»ò½«Êý¸öµµ°¸¿½±´ÖÁÁíһĿ¼¡£
°Ñ¼Æ
-a ¾¡¿ÉÄܽ«µµ°¸×´Ì¬¡¢È¨ÏÞµÈ×ÊÁ϶¼ÕÕÔ­×´ÓèÒÔ¸´ÖÆ¡£
-r Èô source Öк¬ÓÐĿ¼Ãû£¬Ôò½«Ä¿Â¼ÏÂÖ®µµ°¸Òà½ÔÒÀÐò¿½±´ÖÁÄ¿µÄµØ¡£
-f ÈôÄ¿µÄµ ......

¶ÁÊé±Ê¼ÇÖ®¡¶Linux Device Driver¡· £¨Ò»£©

LinuxÉ豸Çý¶¯
 
µÚÒ»Õ É豸Çý¶¯¼ò½é
Çý¶¯³ÌÐòµÄ½ÇÉ«ÊÇÌṩ»úÖÆ£¬¶ø²»ÊDzßÂÔ¡£
±àдÄں˴úÂëÀ´´æÈ¡Ó²¼þ£¬µ«ÊDz»ÄÜÇ¿¼ÓÌرðµÄ²ßÂÔ¸øÓû§(Ö»ÐèÒª±íÏÖ³öÓ²¼þµÄ×î»ù±¾µÄ¹¦ÄÜ£¬ÈçºÎʹÓÃÕâЩ¹¦ÄÜÓÖÓû§×Ô¼ºÑ¡Ôñ)
¶Ô²ßÂÔ͸Ã÷µÄÇý¶¯ÌØÕ÷£ºÖ§³Öͬ²½ºÍÒì²½²Ù×÷¡¢¿ÉÒÔ¶à´Î´ò¿ª¡¢ÀûÓÃÓ²¼þÈ«²¿ÄÜÁ¦¡¢Ã»ÓÐÈí¼þ²ãÌṩ²ßÂÔÏà¹Ø ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ