📄 signal.c
字号:
/* includes */
#include "vxWorks.h"
#include "sigLib.h"
#include "taskLib.h"
#include "stdio.h"
#include "logLib.h"
/* function prototypes */
void catchSIGINT(int);
void sigCatcher(void);
/* globals */
#define NO_OPTIONS 0
#define ITER1 100
#define LONG_TIME 10000
#define HIGHPRIORITY 100
#define LOWPRIORITY 101
int ownId;
void sigGenerator(void) /* task to generate the SIGINT signal */
{
int i, taskId;
STATUS taskAlive;
logMsg("$$$$$$$$$----BEGING----\n",0,0,0,0,0,0);
if((taskId = taskSpawn("signal",100,0x100,20000,(FUNCPTR)sigCatcher,0,0,0,0,0,0,0,
0,0,0)) == ERROR)
printf("taskSpawn sigCatcher failed\n");
ownId = taskIdSelf(); /* get sigGenerator's task id */
taskDelay(10); /* allow time to get sigCatcher to run */
for (i=0; i < ITER1; i++)
{
if ((taskAlive = taskIdVerify(taskId)) == OK)
{
logMsg("++++++++++++SIGINT sinal generated\n",0,0,0,0,0,0);
kill(taskId, SIGINT); /* generate signal */
/* lower sigGenerator priority to allow sigCatcher to run */
taskPrioritySet(ownId,LOWPRIORITY);
}
else /* sigCatcher is dead */
break;
}
printf("\n***************sigGenerator Exited***************\n");
}
void sigCatcher(void) /* task to handle the SIGINT signal */
{
struct sigaction newAction;
int i, j;
newAction.sa_handler = catchSIGINT; /* set the new handler */
sigemptyset(&newAction.sa_mask); /* no other signals blocked */
newAction.sa_flags = NO_OPTIONS; /* no special options */
if(sigaction(SIGINT, &newAction, NULL) == -1)
printf("Could not install signal handler\n");
for (i=0; i < ITER1; i++)
{
logMsg("Normal processing in sigCatcher\n",0,0,0,0,0,0);
/*for (j=0; j < LONG_TIME; j++);*/
taskDelay(1);
}
printf("\n++++++sigCatcher Exited+++++++++\n");
}
void catchSIGINT(int signal) /* signal handler code */
{
logMsg("----------SIGINT signal caught\n",0,0,0,0,0,0);
/* increase sigGenerator priority to allow sigGenerator to run */
taskPrioritySet(ownId,HIGHPRIORITY);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -