|
|||||||||||
| 技術(shù)交流 | 電路欣賞 | 工控天地 | 數(shù)字廣電 | 通信技術(shù) | 電源技術(shù) | 測(cè)控之家 | EMC技術(shù) | ARM技術(shù) | EDA技術(shù) | PCB技術(shù) | 嵌入式系統(tǒng) 驅(qū)動(dòng)編程 | 集成電路 | 器件替換 | 模擬技術(shù) | 新手園地 | 單 片 機(jī) | DSP技術(shù) | MCU技術(shù) | IC 設(shè)計(jì) | IC 產(chǎn)業(yè) | CAN-bus/DeviceNe |
請(qǐng)問(wèn)周公有什么辦法讓一個(gè)進(jìn)程中定時(shí)器和等待消息共存 |
| 作者:上校 欄目:ARM技術(shù) |
#include <stdio.h> #include <signal.h> #include <sys/time.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> #include <sys/shm.h> #include "Ell.h" #include "EllData.h" #include "EllFun.h" UINT8 eltT0Timeout() { printf("TimeOut!\n"); } /*初始化信號(hào)*/ void init_sigaction(void) { struct sigaction act; act.sa_handler=(void *)eltT0Timeout; act.sa_flags=0; sigemptyset(&act.sa_mask); sigaction(SIGALRM,&act,NULL); } /*初始化代碼*/ void init_time() { struct itimerval VALUE; /*定時(shí)3秒鐘*/ VALUE.it_VALUE.tv_sec=3; VALUE.it_VALUE.tv_usec=0; VALUE.it_interval=VALUE.it_VALUE; setitimer(ITIMER_REAL,&VALUE,NULL); } int main() { ellMsgStart(); enlMsgStart(); shmStart(); ShmBufPtr = (ShmPacketBufS *)ShmPtr; init_sigaction(); init_time(); while(1) { MsgPassedS myMsg; myMsg.realMessage = ELS_ALARM_CLEAR; myMsg.msgKey = 1; if(msgrcv(RecvMsgQid, (void *)&myMsg, 1, MSG_TO_RECV, 0) == -1) { printf("read msg error;\n"); return(1); } } return 0; } 在msgrcv(RecvMsgQid, (void *)&myMsg, 1, MSG_TO_RECV, 0) 函數(shù)中收到 一個(gè)信號(hào)后就返回-1,大家有什么辦法讓一個(gè)進(jìn)程中定時(shí)器和等待消息共存?? |
|
|
| 免費(fèi)注冊(cè)為維庫(kù)電子開發(fā)網(wǎng)會(huì)員,參與電子工程師社區(qū)討論,點(diǎn)此進(jìn)入 |
Copyright © 1998-2006 m.58mhw.cn 浙ICP證030469號(hào) |