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 ");
}
Ïà¹ØÎĵµ£º
²é¿´·¢ÐаæÐÅÏ¢£º
lsb_release -a Õâ¸ö×îÏêϸ
²é¿´Äں˺ͲÙ×÷ϵͳλÊý£º
uname -a
64λ²Ù×÷ϵͳÓÐÀàËÆÐÅÏ¢£º.... x86_64 x86_64 x86_64...
32λ²Ù×÷ϵͳÓÐÀàËÆÐÅÏ¢£º.... i686 i686 i386...
²é¿´cpuÐÅÏ¢£º
more /proc/cpuinfo
²é¿´ºÍ¿ØÖÆϵͳ·þÎñ£¨Èç iptables·À»ðǽµÄ¿ªºÍ¹Ø£©£º
chkconfig ²é¿´ºÍÉ趨·þÎñÔÚ²»Í¬ ......
1.Ìí¼Órpm fusionÔ´
rpm -ivh
http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm
http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
2.µ¼Èërpm fusion²Ö¿âµÄÃÜÔ¿
rpm --import http://ATrpms.net/RPM-GPG-KEY.atrpms
3.ÐÞ¸ÄÃÜÔ¿Îļþ
......
ÒýÓÃ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");
}
±£´æ¡£È»ºó´ò¿ªÖնˡ£
±àÒëÊÇʲôÃüÁû°ì·¨£¬ÎÊÏÂͬѧ¡£°¢Áé¸æËßÎÒ£º ......
Ò»£®Ìî¿ÕÌ⣺
1. ÔÚLinuxϵͳÖУ¬ÒÔ Îļþ ·½Ê½·ÃÎÊÉ豸 ¡£
2. LinuxÄÚºËÒýµ¼Ê±£¬´ÓÎļþ /etc/fstab ÖжÁÈ¡Òª¼ÓÔصÄÎļþϵͳ¡£
3. LinuxÎļþϵͳÖÐÿ¸öÎļþÓà i½Úµã À´±êʶ¡£
4. È«²¿´ÅÅÌ¿éÓÉËĸö²¿·Ö×é³É£¬·Ö±ðΪÒýµ¼¿é ¡¢×¨ÓÃ¿é ¡¢ i½Úµã±í¿é ºÍÊý¾Ý´æ´¢¿é¡£
5. Á´½Ó·ÖΪ£º Ó²Á´½Ó ºÍ ·ûºÅÁ´½Ó ¡£
6. ³¬¼¶¿é°üº¬ÁËi½ ......