VxWorks系统中的signal使用?

panyf_2k 2002-01-25 07:14:27
我有如下程序:
#include <vxWorks.h>
#include <sigLib.h>
#include <taskLib.h>
#include <stdio.h>

void catchSIGINT(int);
void sigCatcher(void);

#define NO_OPTIONS 0
#define ITER1 100
#define LONG_TIME 1000000
#define HIGHPRIORITY 100
#define LOWPRIORITY 101
int ownId;


void sigGenerator(void)
{
int i,j,taskId;
STATUS taskAlive;

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();

taskDelay(30);

for(i=0;i<ITER1;i++)
{
if((taskAlive=taskIdVerify(taskId))==OK)
{
printf("+++++++++++++++++++++++SIGINT signal
generated\n");

kill(taskId,SIGINT);
taskPrioritySet(ownId,LOWPRIORITY);
}
else
break;
}
printf("\n******************sigGeneratro
Exited***************\n");
}

void sigCatcher(void)
{
struct sigaction newAction;
int i,j;

newAction.sa_handler=catchSIGINT;
sigemptyset(&newAction.sa_mask);
newAction.sa_flags=NO_OPTIONS;

if(sigaction(SIGINT,&newAction,NULL)==-1)
printf("Could not install signal handler\n");

for(i=0;i<ITER1;i++)
{
for(j=0;j<LONG_TIME;j++);
printf("Normal processing in sigCatcher\n");
}
printf("\n+++++++++++++++++++++++++sigCatcher
Exited++++++++++++++++++\n");
}

void catchSIGINT(int signal)
{
printf("-----------------SIGINT signal caught\n");
taskPrioritySet(ownId,HIGHPRIORITY);
}
请问一个问题:
怎么在运行结果中没有"-------------------SIGINT signal caught"
也就是void catchSIGINT()函数好像没有调用,是这样吗?
望请高手指点!谢谢!
...全文
290 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
panyf_2k 2002-03-01
  • 打赏
  • 举报
回复
难道有关信号和中断的例子就只能到目标机上进行运行?
panyf_2k 2002-03-01
  • 打赏
  • 举报
回复
我只是在单机上模拟.
我所提到的posix和bsd有关系吗?
wenyong 2002-03-01
  • 打赏
  • 举报
回复
你是在目标机上运行吗?还是在模拟器上?
我在目标机上运行时可以打出结果。
panyf_2k 2002-02-26
  • 打赏
  • 举报
回复
wenyong在吗?
帮我看一下!
panyf_2k 2002-02-21
  • 打赏
  • 举报
回复
我按照你所述运行程序,还是没有打印---------SIGNT signal caught
我看到signal有POSIX和BSD环境之分.
我的开发环境是基于win2000下的vxworks开发
不知有这方面的原因?
wenyong 2002-02-08
  • 打赏
  • 举报
回复
#include <vxWorks.h>
#include <sigLib.h>
#include <taskLib.h>
#include <stdio.h>

void catchSIGINT(int);
void sigCatcher(void);

#define NO_OPTIONS 0
#define ITER1 100
#define LONG_TIME 1000000
#define HIGHPRIORITY 100
#define LOWPRIORITY 101
int ownId;


void sigGenerator(void)
{
int i,j,taskId;
STATUS taskAlive;

printf("\n******************sigGenerator Started***************\n");

if( sigInit() == ERROR)
{
printf("signal init error\r\n");
}
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();

taskDelay(30);

for(i=0;i<ITER1;i++)
{
if((taskAlive=taskIdVerify(taskId))==OK)
{
printf("+++++++++++++++++++++++SIGINT signal generated\n");

kill(taskId,SIGINT);
taskPrioritySet(ownId,LOWPRIORITY);
}
else
break;
}
printf("\n******************sigGenerator Exited***************\n");
}

void sigCatcher(void)
{
struct sigaction newAction,oldAction;
int i,j;
STATUS saStatus;

printf("\n+++++++++++++++++++++++++sigCatcher Started++++++++++++++++++\n");

newAction.sa_handler=catchSIGINT;
sigemptyset(&newAction.sa_mask);
newAction.sa_flags=NO_OPTIONS;

if((saStatus = sigaction(SIGINT,&newAction,&oldAction))== ERROR)
{
printf("Could not install signal handler\n");
return ;
}
else
printf("SIGINT signal installed successfully!\r\n");

pause();

if((saStatus = sigaction(SIGINT,&oldAction,NULL))==ERROR)
printf("Count old uninstall signal handler\n");
else
printf("SIGINT signal uninstalled successfully!\r\n");

printf("\n+++++++++++++++++++++++++sigCatcher Exited++++++++++++++++++\n");
}

void catchSIGINT(int signal)
{
printf("-----------------SIGINT signal caught\n");
taskPrioritySet(ownId,HIGHPRIORITY);
}
wenyong 2002-02-07
  • 打赏
  • 举报
回复
忘了调用sigInit函数初始化VxWorks的信号机制,我已经试过了,SIGINT signal caught 打出来了
wenyong 2002-02-07
  • 打赏
  • 举报
回复
我来研究一下,等等我
turbopeng 2002-01-29
  • 打赏
  • 举报
回复
`up
panyf_2k 2002-01-26
  • 打赏
  • 举报
回复
??

19,519

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 嵌入开发(WinCE)
社区管理员
  • 嵌入开发(WinCE)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧