LinuxÐźÅ
from: http://cc.byexamples.com/20070520/tap-the-interrupt-signal/
When you hit control+c, you are actually send a SIGINT ( Interrupt signal ) to your program. By default, your program will be terminated after receiving SIGINT. But you can change the way of handling Interrupt signal.
Some of the application tends to ignore SIGINT. You can easily do that with sigaction.
#include<stdio.h>
#include<signal.h>
void bypass_sigint(int sig_no)
{
}
int main()
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = &bypass_sigint;
sigaction(SIGINT, &sa,NULL);
while(1)
{
sleep(1);
printf("do nothing \n ");
}
return 0;
}
Create a void function that intentionally do nothing. Create a sigaction structure variable, set the sa_handle point to the void fucntion. At last calling sigaction function, telling the system, while receiving SIGINT, call the void function.
Observed that the sigaction have to take 3 parameters, and the third param is to store the default sigaction structure for SIGINT. specify NULL for ignoring that.
What if I wanna tap the interrupt signal, do some operations and then allows the default SIGINT operation carry on? This can be very useful, for example, I want my program to log whatever in my memory to a file before the program terminate.
#include<stdio.h>
#include<signal.h>
#include<string.h>
struct sigaction osa;
void bypass_sigint(int sig_no)
{
printf("I tap SIGINT and returns back \n");
sigaction(SIGINT,&osa,NULL);
kill(0,SIGINT);
}
int main()
{
struct sigaction sa,osa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = &bypass_sigint;
sigaction(SIGINT, &sa,&osa);
while(1)
{
sleep(1);
printf("do nothing \n ");
}
Ïà¹ØÎĵµ£º
Èç¹ûÊÇwinϵģ¬ÎÒ¸öÈËÍÆ¼öËÑË÷ÏÂÒ»¼ü°²×°°ü£¡ÎÒÓõľÍÊÇphp+mysql£¨×÷Õ߽УºÑ§Ï°À×·æºÃ°ñÑù£© °²×°Ò»ÏÂÈ«¶¼¿ÉÒÔÕý³£Ê¹ÓÃÁË£¬²»ÐèÒªµ÷Õû£¡
ÏÂÃæÊÇLinuxϰ²×°·½·¨£¡
¡¡1¡¢ÏÂÔØMySQLµÄ°²×°Îļþ
¡¡¡¡°²×°MySQLÐèÒªÏÂÃæÁ½¸öÎļþ£º
¡¡¡¡MySQL-server-5.0.26-0.i386.rpm
¡¡¡¡MySQL-client-5.0.26-0.i386.rpm
¡¡¡¡ÏÂÔØµØÖ·Î ......
¼Ù¶¨Äã»áCÓïÑÔ£¬¶øÇÒÃ÷°×CÓïÑÔÃæÏò¶ÔÏó±à³ÌµÄschme£¬¶Ô²Ù×÷ϵͳ£¨°üÀ¨µ÷¶È£¬ÄÚ´æ·ÖÅ䣬·ÖÒ³£¬Í¬²½£¬etc£©±È½ÏÁ˽⡣ÄÇôÄã¿ÉÒÔ°´ÕÕÈçÏÂ˳ÐòѧϰLinux Äںˡ£
1.¿´Linux Device DriverÕâ±¾Êé¡£ÕâÊÇΪÁËÈÃÄã¶®µÃ±àÒëÄÚºËÄ£¿éµÄ·½·¨¡£»¹ÓÐΪLinux¸÷ÖÖÉ豸ÁôÏÂһЩӡÏó¡£Í¬Ê±Ò»±é¿´ÊéÒ»±ß¿´Ä³Ð©É豸µÄÔ´´ú ......
ssh³£ÓÃÃüÁî
Ŀ¼£º
1. Basic Instructions /»ù±¾Ö¸Áî
2. wget /ÏÂÔØ¹¤¾ß
3. Crontab /¶¨Ê±ÈÎÎñ
4. tar/tar.gz /ѹËõÎļþ
5. vi /±à¼Æ÷
1. Basic Instructions»ù±¾²Ù×÷ÃüÁî
ͨ³£À´Ëµ£¬Ê¹ÓÃ"$[Instructions] --help"¿ÉÒÔ»ñµÃÒÔϸ÷¸öÃüÁî[instructions]µÄ°ïÖú£¬°üº¬Æä²ÎÊýÁбíµÄ¶¨Òå¡£
-ls Áгöµ±Ç°Îļþ¼Ð ......
ÒýÓÃhttp://www.linuxtone.org/html/76/t-2776.html
ÓÐʱºònginx£¬apache£¬mysql£¬php±àÒëÍêÁËÏë¿´¿´±àÒë²ÎÊý¿ÉÒÔÓÃÒÔÏ·½·¨
nginx±àÒë²ÎÊý£º
#/usr/local/nginx/sbin/nginx -V
CODE:
nginx version: nginx/0.6.32
built by gcc 4.1.2 20071124 (Red Hat 4.1.2-42)
configure arguments: --user=www --group=www --p ......
µÚÒ»´ÎÔÚLinuxϱà³Ì¡£ºÇºÇ
ÔÚÍøÉÏËÑË÷ÁËÒ»ÏÂÔõôÑùÔÚLinuxϱà³Ì¡£ËµÊÇÓÃGeditдºÃ´úÂ룬Ȼºó±£´æ.c¸ñʽÎļþ¡£È»ºóµ½Öն˱àÒë¡£
´ò¿ªGedit.ÀÏ¹æ¾Ø£¬ÏÈÀ´¸öHello.c
#include <stdio.h>
main()
{
printf("Hello~!Vimo~~\n\n");
}
±£´æ¡£È»ºó´ò¿ªÖÕ¶Ë¡£
±àÒëÊÇʲôÃüÁû°ì·¨£¬ÎÊÏÂͬѧ¡£°¢Á鏿ËßÎÒ£º ......