C Library Functions -sigfillset()

C Standard Library - <signal.h>

Description

sigfillsetThe function is a function in the C standard library, used to initialize a signal set so that it contains all defined signals. This function is defined in<signal.h>In the header file.

Syntax

int sigfillset(sigset_t *set);

Parameter

  • sigset_t *set: points to asigset_tA variable of type, which will be initialized to a signal set containing all signals.

Return Value

  • Returns 0 on success.
  • Returns -1 on failure, and setserrnoto indicate the type of error.

Example

The following is an example usingsigfillsetAn example program for the function initializing a signal set. The program initializes a signal set to contain all signals and checks whether it contains a specific signal.

Example

#include <stdio.h>
#include <signal.h>

int main() {
    sigset_t set;

    // Initialize the signal set, containing all signals
    if (sigfillset(&set) == -1) {
        perror("sigfillset");
        return 1;
    }

    // Check whether the signal set contains SIGINT
    if (sigismember(&set, SIGINT)) {
        printf("SIGINT is in the set\n");
    } else {
        printf("SIGINT is not in the set\n");
    }

    return 0;
}

A possible output of running the above example program is as follows:

SIGINT is in the set

The program initializes the signal set to contain all signals and checks whether the signal set containsSIGINTsignal, the results show thatSIGINTThe signal is in the signal set.

Explanation

  • sigset_t set;: defines a signal set variable.
  • UsagesigfillsetThe function initializes the signal set to contain all signals.
  • UsagesigismemberThe function checks whether the signal set containsSIGINTsignal.
  • The output showsSIGINTThe signal is in the initialized signal set.

Notes

  • sigfillsetThe function is used to initialize a signal set so that it contains all defined signals.
  • The initialized signal set can be used for subsequent signal operations, such as removing specific signals.

C Standard Library - <signal.h>

other extensions