Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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
#include
#include
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());
signal(SIGALRM, sigroutine);
signal(SIGVTALRM, sigroutine);
value.it_value.tv_sec = 1;
value.it_value.tv_usec = 0;
value.it_interval.tv_sec = 1;
value.


Ïà¹ØÎĵµ£º

ʵսLinux Bluetooth±à³Ì (Æß) SDPЭÒé

Service Discovery Protocol(SDP)ÌṩһÖÖÄÜÁ¦£¬ÈÃÓ¦ÓóÌÐòÓз½·¨·¢ÏÖÄÄÖÖ·þÎñ¿ÉÓÃÒÔ¼°ÕâÖÖ·þÎñµÄÌØÐÔ¡£
·þÎñ·¢ÏÖЭÒé(SDP»òBluetooth SDP)ÔÚÀ¶ÑÀЭÒéÕ»ÖжÔÀ¶ÑÀ»·¾³ÖеÄÓ¦ÓóÌÐòÓÐÌØÊâµÄº¬Ò⣬·¢ÏÖÄĸö·þÎñÊÇ¿ÉÓõĺÍÈ·¶¨ÕâЩ¿ÉÓ÷þÎñµÄÌØÕ÷¡£SDP¶¨ÒåÁËbluetooth client·¢ÏÖ¿ÉÓÃbluetooth server·þÎñºÍËüÃǵÄÌØÕ÷µÄ·½·¨¡£ ......

linux PS1 Ìáʾ·û¶¨Òå

PS1£º¾ÍÊÇÓû§Æ½Ê±µÄÌáʾ·û¡£
¡¡¡¡PS2£ºµÚÒ»ÐÐûÊäÍ꣬µÈ´ýµÚ¶þÐÐÊäÈëµÄÌáʾ·û¡£
¡¡¡¡LinuxϵͳÌáʾ·ûÊÇÓÃϵͳ±äÁ¿PS1À´¶¨ÒåµÄ¡£Ò»°ãϵͳĬÈϵÄÐÎʽÊÇ£º[username@host ¹¤×÷Ŀ¼]$.
¡¡¡¡ÓÃecho $PS1¿ÉÒԵõ½PS1µÄÖµ£¬¼´PS1="[\u@\h \w]"\$
¡¡¡¡µÇ¼ºó¿ÉÒÔ¸ü¸ÄPS1µÄÏÔʾÑùʽ£¬µ«Êǵ±Í˳öÖØÆôµÇ¼½øÈëϵͳºó£¬ÑùʽÓÖ±ä³ ......

linux c ÕýÔò±í´ïʽ

×î½üÓÐÕâô¸öÐèÇó,
c¸ã¸ãÕýÔò,
±Ï¾¹Regular Expression soÇ¿´ó^_^
±ê×¼µÄCºÍC+
+
¶¼²»Ö§³ÖÕýÔò±í´ïʽ£¬µ«ÓÐһЩº¯Êý¿â¿ÉÒÔ¸¨ÖúC/
C+
+
³ÌÐòÔ±Íê³ÉÕâÒ»¹¦ÄÜ£¬ÆäÖÐ×îÖøÃûµÄµ±ÊýPhilip HazelµÄPerl-
Compatible Regular Expression¿â£¬Ðí¶àLinux·¢Ðа汾¶¼´øÓÐÕâ¸öº¯Êý¿â¡£
±àÒëÕýÔò±í´ïʽ
ΪÁËÌá¸ßЧÂÊ£¬ÔÚ½«Ò»¸ö× ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ