Skip to main content

Signals in VxWorks: Asynchronous Notifications Between Tasks

·401 words·2 mins
VxWorks RTOS Signals IPC Asynchronous Embedded Systems Programming Tutorial
Table of Contents
VxWorks Programming Tutorial for Beginners - This article is part of a series.
Part 15: This Article

πŸš€ Introduction
#

Signals in VxWorks are a lightweight asynchronous communication mechanism.
They allow one task to notify another task (or itself) that an event has occurred.

Think of signals as software interrupts:

  • Sent to tasks at any time.
  • Trigger a signal handler (callback function).
  • Great for asynchronous events like timers, I/O, or inter-task alerts.

🧩 Key Concepts of Signals
#

  • Signal Numbers β†’ Each signal is identified by a number (SIGUSR1, SIGUSR2, etc.).
  • Handlers β†’ Tasks can register a function to handle signals.
  • Delivery β†’ A signal can be queued or replace existing ones depending on settings.

πŸ’» Example: Using Signals in VxWorks
#

We’ll demonstrate:

  1. A signal handler function.
  2. A task that waits for signals.
  3. A task that sends signals to another.

Code Example
#

#include <vxWorks.h>
#include <taskLib.h>
#include <signal.h>
#include <sigLib.h>
#include <stdio.h>
#include <unistd.h>

int targetTid;

// Signal handler
void mySignalHandler(int signo)
{
    printf("Task %d: Received signal %d\n", taskIdSelf(), signo);
}

// Task that registers a signal handler
void signalReceiverTask()
{
    struct sigaction sa;

    sa.sa_handler = (void (*)(int))mySignalHandler;
    sa.sa_flags = 0;
    sigemptyset(&sa.sa_mask);

    // Register handler for SIGUSR1
    sigaction(SIGUSR1, &sa, NULL);

    printf("Receiver task ready (TID=%d). Waiting for signals...\n", taskIdSelf());

    while (1)
    {
        taskDelay(200); // Idle loop
    }
}

// Task that sends signals
void signalSenderTask()
{
    while (1)
    {
        if (targetTid != 0)
        {
            kill(targetTid, SIGUSR1);
            printf("Sender: Sent SIGUSR1 to TID=%d\n", targetTid);
        }
        taskDelay(100); // ~1 second
    }
}

void usrAppInit(void)
{
    // Spawn receiver
    targetTid = taskSpawn("tRecv", 100, 0, 4000, (FUNCPTR)signalReceiverTask,
                          0,0,0,0,0,0,0,0,0,0);

    // Spawn sender
    taskSpawn("tSend", 110, 0, 4000, (FUNCPTR)signalSenderTask,
              0,0,0,0,0,0,0,0,0,0);
}

πŸ“ Explanation of the Code
#

  1. Signal Handler Registration

    • sigaction() installs a handler for SIGUSR1.
    • Any time SIGUSR1 is sent, mySignalHandler() executes.
  2. Receiver Task

    • Registers the handler and enters an idle loop.
  3. Sender Task

    • Uses kill() to send SIGUSR1 to the receiver’s TID.

⚑ What You’ll See
#

Expected output:

Receiver task ready (TID=1234). Waiting for signals...
Sender: Sent SIGUSR1 to TID=1234
Task 1234: Received signal 16
Sender: Sent SIGUSR1 to TID=1234
Task 1234: Received signal 16
...

πŸ” Key Takeaways
#

  • Signals are lightweight asynchronous notifications in VxWorks.
  • Use them for event-driven programming.
  • Great for timers, I/O completions, or inter-task alerts.

βœ… Wrap-Up
#

In this tutorial, you learned:

  • How to register and handle signals in VxWorks.
  • How one task can send signals to another.
  • How signals enable asynchronous communication.

In the next blog, we’ll explore Watchdog Timers in VxWorks: Monitoring Task Health.

VxWorks Programming Tutorial for Beginners - This article is part of a series.
Part 15: This Article

Related

Message Passing with Pipes in VxWorks
·460 words·3 mins
VxWorks RTOS Pipes Message Passing IPC Embedded Systems Programming Tutorial
Shared Memory Communication in VxWorks
·460 words·3 mins
VxWorks RTOS IPC Shared Memory Embedded Systems Programming Tutorial
Inter-Task Communication with Message Queues in VxWorks
·459 words·3 mins
VxWorks RTOS IPC Message Queues Embedded Systems Programming Tutorial