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

LinuxϵĶ¨Ê±Æ÷£ºalarm()Óë setitimer()

LinuxϵĶ¨Ê±Æ÷ÓÐÁ½ÖÖ£¬ÒÔÏ·ֱð½éÉÜ£º
 
1¡¢alarm
 
Èç¹û²»ÒªÇóºÜ¾«È·µÄ»°£¬ÓÃalarm()ºÍsignal()¾Í¹»ÁË
 
unsigned int alarm(unsigned int seconds)
 
º¯Êý˵Ã÷:
alarm()ÓÃÀ´ÉèÖÃÐźÅSIGALRMÔÚ¾­¹ý²ÎÊýsecondsÖ¸¶¨µÄÃëÊýºó´«Ë͸øÄ¿Ç°µÄ½ø³Ì¡£Èç¹û²ÎÊýsecondsΪ0£¬Ôò֮ǰÉèÖõÄÄÖÖӻᱻȡ
Ïû£¬²¢½«Ê£ÏµÄʱ¼ä·µ»Ø¡£
 
·µ»ØÖµ: ·µ»Ø֮ǰÄÖÖÓµÄÊ£ÓàÃëÊý£¬Èç¹û֮ǰδÉèÄÖÖÓÔò·µ»Ø0¡£
 
alarm()Ö´Ðк󣬽ø³Ì½«¼ÌÐøÖ´ÐУ¬ÔÚºóÆÚ(alarmÒÔºó)µÄÖ´Ðйý³ÌÖн«»áÔÚ
secondsÃëºóÊÕµ½ÐźÅSIGALRM²¢Ö´ÐÐÆä´¦Àíº¯Êý¡£
 
 
#include <unistd.h> //pause alarm
#include <signal.h> //SIGALRM
void sigalrm_fn(int sig)
{
printf("alarm!\n");
alarm(2);
return;
}
int main(void)
{
signal(SIGALRM, sigalrm_fn);
alarm(1);
while(1)
pause();
}
 
2¡¢setitimer()
 
int setitimer(int which, const struct
itimerval *value, struct itimerval *ovalue));
 
setitimer()±Èalarm¹¦ÄÜÇ¿´ó£¬Ö§³Ö3ÖÖÀàÐ͵Ķ¨Ê±Æ÷£º
 
ITIMER_REAL : ÒÔϵͳÕæʵµÄʱ¼äÀ´¼ÆË㣬ËüËͳöSIGALRMÐźš£
 
ITIMER_VIRTUAL :
-ÒԸýø³ÌÔÚÓû§Ì¬Ï»¨·ÑµÄʱ¼äÀ´¼ÆË㣬ËüËͳöSIGVTALRMÐźš£
 
ITIMER_PROF :
ÒԸýø³ÌÔÚÓû§Ì¬ÏºÍÄÚºË̬ÏÂËù·ÑµÄʱ¼äÀ´¼ÆË㣬ËüËͳöSIGPROFÐźš£
 
setitimer()µÚÒ»¸ö²ÎÊýwhichÖ¸¶¨¶¨Ê±Æ÷ÀàÐÍ£¨ÉÏÃæÈýÖÖÖ®Ò»£©£»µÚ¶þ¸ö²ÎÊýÊÇ
½á¹¹itimervalµÄÒ»¸öʵÀý£»µÚÈý¸ö²ÎÊý¿É²»×ö´¦Àí¡£
 
setitimer()µ÷Óóɹ¦·µ»Ø0£¬·ñÔò·µ»Ø-1¡£
 
ÏÂÃæÊǹØÓÚsetitimerµ÷ÓõÄÒ»¸ö¼òµ¥Ê¾·¶£¬ÔÚ¸ÃÀý×ÓÖУ¬Ã¿¸ôÒ»Ãë·¢³öÒ»¸ö
SIGALRM£¬Ã¿¸ô0.5Ãë·¢³öÒ»¸öSIGVTALRMÐźÅ:
 
 
#include
#include
#include
#include
#include
#include
int sec;
void sigroutine(int signo){
switch (signo){
case SIGALRM:
printf("Catch a signal -- SIGALRM \n");
signal(SIGALRM, sigroutine);
break;
case SIGVTALRM:
printf("Catch a signal -- SIGVTALRM \n");
signal(SIGVTALRM, sigroutine);
break;
}
return;
}
int main()
{
struct itimerval value, ovalue, value2; //(1)
sec = 5;
printf("process id is %d\n", getpid());
sign


Ïà¹ØÎĵµ£º

ÔÚlinuxÏÂʵÏÖweb qqµÄ×ÀÃ滯


´´½¨×ÀÃæͼ±ê
Ä¿Ç°½«ÍøÂçÓ¦ÓÃÀ©Õ¹µ½×ÀÃæÊÇÒ»¸öÇ÷ÊÆ£¬´æÔÚןܶà½â¾ö·½°¸£¬±¾ÎÄÒÔ Mozilla Prism ΪÀý£¬ÀàËƵķ½·¨Í¬ÑùÊÊÓÃÓÚ Google Chrome ¡£
1. µ½ Mozilla Prism µÄÍøÕ¾ÉÏÏÂÔØ Prism£¬µã»÷ Download Now Ö®ºó»áÌáʾÓÐÁ½ÖÖ£¬Ò»ÖÖÊÇÒÔ Mozilla Firefox À©Õ¹µÄ·½Ê½£¬ÊʺÏÒѾ­°²×°ÓÐ Firefox µÄÅóÓÑ£»Ò»Ö ......

linux ƽ̨ӦÓóÌÐòÔõôÑùͨ¹ýUSB¿ØÖÆ

£¨1£©Óû§Ä£Ê½USB
      usbfsÐéÄâÎļþϵͳÔÊÐí´ÓÓû§¿Õ¼äÒÔԭʼ·½Ê½·ÃÎÊUSBÉ豸¡£usbfsͨ³£¹ÒÔØÔÚ/proc/bus/usb/ÉÏ£¬usbfsÊ÷°üº¬ÁËϵͳÖÐÓëÿ¸öUSB¿ØÖÆÆ÷£¨»ò×ÜÏߣ©¶ÔÓ¦µÄĿ¼£¬Ã¿¸öĿ¼ÒÀ´Î°üº¬ÁËÓë¸Ã×ÜÏßÉϵÄUSBÉ豸Ïà¶ÔÓ¦µÄ½áµã¡£
      ΪÁ˸üºÃµØÀí½âusbfs£¬ÎÒà ......

linux ¶¨Ê±ÈÎÎñ crontabµÄÓ÷¨

crontabµÄÓ÷¨---linux¶¨Ê±ÈÎÎñ
2008Äê07ÔÂ30ÈÕ ÐÇÆÚÈý ÏÂÎç 01:00
crontabµÄÓ÷¨---linux¶¨Ê±ÈÎÎñ
Step 1:
    ʹÓÃÃüÁîcrontab
-e±à¼­Ò»¸ö¶¨Ê±Ö´ÐеÄÈÎÎñ»òÔÚ/var/spool/cron/crontabsĿ¼ÏÂн¨Ò»¸öÓë×Ô¼ºÓû§ÃûÏàͬµÄÈÎÎñ.
    ¼´:
   
#ÿ¸ôÒ»·ÖÖÓÖ´ÐÐÒ»´Îº ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ