Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Signal to realize Mask Operation in vxworks

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use Signal to achieve mask operation in vxworks. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

In Kernel, each Task has a mask (Mask) for Signal. A mask value of 1 means that the Signal is intercepted, that is, the Signal; is not processed and a mask value of 0 means that the Signal is processed. And by default, each Task processes the Signal sent to it, but the default solution is SIG_IGN (discard / ignore). Therefore, to respond to Signal, you need to manually attach the processing mechanism of Signal. Let's take a look at the operations related to Mask today.

/ * Source of Signal * / # define SI_SYNC 0 / * (Not posix) gernerated by hardware * / # define SI_USER-1 / * signal from kill () function * / # define SI_QUEUE-2 / * signal from sigqueue () function * / # define SI_TIMER-3 / * signal from expiration of a timer * / # define SI_ASYNCIO-4 / * signal from completion of async Igamo * / # define SI_MESGQ-5 / * signal from arrival of a message * / # define SI_CHILD-6 / * signal from child Stopped or terminated * / # define SI_KILL SI_USER

Typedef unsigned long long sigset_t

/ * POSIX: clear the Signal mask, which is often used to initialize * / int sigemptyset (sigset_t * pSet)

/ * POSIX: contrary to sigemptyset (), set the bit of all Signal to 1 * / int sigfillset (sigset_t * pSet)

/ * POSIX: add signum * / int sigaddset (sigset_t * pSet, int signum) to the mask pSet

/ * POSIX: remove signum * / int sigdelset (sigset_t * pSet, int signum) from the mask pSet

/ * POSIX: whether signum * / int sigismember (sigset_t * pSet, int signum) is included in the mask pSet

/ * POSIX: get the blocked Signal * / int sigpending (sigset_t * pSet) in the current task

# define SIG_BLOCK 1#define SIG_UNBLOCK 2#define SIG_SETMASK 3ax * POSIX: modify / view the mask. Each bit bit represents a Signal, * 1 indicates intercept, 0 indicates response to * pSet non-empty time, modify the task's Signal mask * pOldSet non-empty time View the original Signal mask of the task * how is modified * SIG_BLOCK-add pSet * SIG_UNBLOCK to the original mask-add pSet * SIG_SETMASK to the original source code-set the mask to pSet * / int sigprocmask (int how, sigset_t * pSet, sigset_t * pOldSet)

/ * set mask * similar to sigprocmask (SIG_SETMASK, mask,...) * only low 32 bits are supported * not recommended * / int sigsetmask (int mask)

/ * add mask * similar to sigprocmask (SIG_BLOCK, mask,...) * only low 32 bits are supported * not recommended * / int sigblock (int mask)

Run an example to see the effect of the mask

/ * * use of Signal * official account: VxWorks567 * / # include / * printf () * / # include / * sigaction () * / # include / * pause () * / # include / * taskName ()

Static void myHandler (int sigNum,siginfo_t * pInfo,void * pContext) {printf ("\ nreceived Signal (#% d) from% d) with the value% d\ n", pInfo- > si_code, sigNum, pInfo- > si_value.sival_int); printf ("task% s mask is 0x6llx\ n", taskName (0), ((struct sigcontext *) pContext)-> sc_mask);}

Void testSig () {struct sigaction newAction;sigset_t newSet;sigset_t oldSet

TaskDelay (10)

/ * Register the Signal handler to SIGUSR1 * / newAction.sa_sigaction = myHandler; newAction.sa_mask = 0; newAction.sa_flags = SA_SIGINFO; sigaction (SIGUSR1, & newAction, NULL)

/ * intercept SIGUSR2 * / sigemptyset (& newSet); sigaddset (& newSet, SIGUSR2); sigprocmask (SIG_BLOCK, & newSet, & oldSet); printf ("\ nThe original mask is 0x6llx\ n", oldSet)

/ * View current mask * / sigprocmask (0, NULL, & newSet); printf ("current mask is 0x6llx\ n", newSet); pause (); printf ("Task% s is activated by Signal\ n", taskName (0));}

/ * send SIGUSR1 to testSig * / void giveSig (int tId) {union sigval value; value.sival_int = 100scape printf ("send Signal (#% d) to task% s with the value% d\ n", SIGUSR1, taskName (tId), value.sival_int); sigqueue (tId, SIGUSR1, value);}

Start a Task, hook up the processing function of SIGUSR1, and block the SIGUSR2. The execution effect is as follows

You can see that no Signal will be blocked before setting the mask, that is, the original mask is 64 zeros. This is the end of the article on "how to use Signal in vxworks to achieve mask operation". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report