- 论坛徽章:
- 0
|
20可用积分
如下程序(作为Tuxedo的客户端连接Tuxedo),第一次Ctrl+C后,屏幕输出:
Catch SIGINT, 这个是正常的; 但由于在solaris下, signal函数处理后如果不重新安装信号
处理函数,那么下次再Ctrl+C后,进程是会退出的; 但如下的程序Ctrl+C多次后还是显示
Catch SIGINT, 进程不退出, 不知道什么原因,请大家指教:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <signal.h>
#include <atmi.h>
#include <fml32.h>
#include "atmi.h"
//#include "userlog.h"
//#include "fml32.h"
void catchControlC(int cCtrlChar)
{
if( cCtrlChar == SIGINT)
{
printf("Catch SIGINT\n");
}
}
int main()
{
signal(SIGINT, &catchControlC);
if (tpinit((TPINIT *) NULL) == -1) {
(void) fprintf(stderr, "Tpinit failed\n");
(void) fprintf(stderr, "Error No = [%d]\n",tperrno);
exit(1);
} else {
(void) fprintf(stderr, "Tpinit success\n");
}
while (1) sleep(1);
return 0;
}
为了对比,如下简单例子程序,如果进行两次Ctrl+C,那么整个进程就会退出:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
void catchControlC(int cCtrlChar)
{
if( cCtrlChar == SIGINT)
{
printf("Catch SIGINT\n");
}
}
int main()
{
signal(SIGINT, &catchControlC);
while (1) sleep(1);
return 0;
} |
|