IPC

Overview

Provides functions and structures related to inter-process communication (IPC), including signals, semaphores, and message queues.

Since:

1.0

Version:

1.0

Summary

Files

File Name

Description

ipcstat.h

Defines the macros related to the IPC functions.

mqueue.h

Provides message queue operation functions and related structures.

semaphore.h

Provides functions and structures related to semaphore operations.

signal.h

Provides signal operation functions and structures, including changing the signal processing mode and the process signal mask set.

ipc.h

Defines IPC-related macros.

Data Structures

Data Structure Name

Description

mq_attr

Describes message queue attributes.

sem_t

Defines semaphores.

sigaltstack

Describes a signal stack.

ucontext

Describes the user execution context.

<a href=”sigset_t.md”>sigset_t

Defines a signal set.

sigaction

Defines the signal processing actions and related attributes. You can use the structures to change the processing actions or attributes.

sigval

Describes signal values in different cases.

<a href=”si_fields.md”>__si_fields

Describes signal information.

sigevent

Describes asynchronous notifications.

Macros

Macro Name and Value

Description

IPC_STAT    2

Defines the input parameter used to obtain information from the kernel.

SEM_FAILED    ((sem_t )0)

Defines the semaphore failure flag.

SA_NOCLDSTOP   1

Stops a child process without sending the SIGCHLD signal.

SA_NOCLDSTOP   0x00000001

Stops a child process without sending the SIGCHLD signal.

SA_NOCLDWAIT    2

Sets the SIGCHLD flag to prevent zombie processes.

SA_NOCLDWAIT    0x00000002

Sets the SIGCHLD flag to prevent zombie processes.

SA_SIGINFO   4

Transfers the siginfo_t structure with the signal.

SA_SIGINFO   0x00000004

Transfers the siginfo_t structure with the signal.

SA_ONSTACK   0x08000000

Uses the signal stack specified by sigaltstack for signal processing.

SA_ONSTACK   0x08000000

Uses the signal stack specified by sigaltstack for signal processing.

SA_RESTART    0x10000000

Obtains the restart signal.

SA_RESTART    0x10000000

Obtains the restart signal.

SA_NODEFER   0x40000000

The signals being processed are not masked during signal processing.

SA_NODEFER   0x40000000

The signals being processed are not masked during signal processing.

SA_RESETHAND    0x80000000

The default processing mode is restored after the signal processing is complete.

SA_RESETHAND    0x80000000

The default processing mode is restored after the signal processing is complete.

SA_RESTORER    0x04000000

Not intended for application use. This flag is used by C libraries to indicate that the sa_restorer field contains the address of a trampoline.

SA_RESTORER    0x04000000

Not intended for application use. This flag is used by C libraries to indicate that the sa_restorer field contains the address of a trampoline.

MINSIGSTKSZ   2048

Defines the minimum size of the replaceable signal stack.

MINSIGSTKSZ   2048

Defines the minimum size of the replaceable signal stack.

SIGSTKSZ   8192

Defines the size of a signal stack.

SIGSTKSZ   8192

Defines the size of a signal stack.

_NSIG    65

Number of supported signals.

_NSIG_BPW    BITS_PER_LONG

Number of bits occupied by a word.

_NSIG_WORDS    (_NSIG / _NSIG_BPW)

Number of words required by all signals.

SIGHUP    1

Hangs up a process.

SIGINT    2

Interrupts a process from keyboard.

SIGQUIT    3

Exits a process from keyboard. A core file is generated.

SIGILL    4

Illegal instruction.

SIGTRAP    5

Breakpoint, used for debugging.

SIGABRT    6

Abnormal termination.

SIGIOT    6

Equivalent to SIGABRT.

SIGBUS    7

Invalid address access.

SIGFPE    8

Floating-point exceptions.

SIGKILL    9

Forcibly stops a process.

SIGUSR1    10

User-defined signal 1.

SIGSEGV    11

Illegal memory access.

SIGUSR2    12

User-defined signal 2.

SIGPIPE    13

The pipe is broken.

SIGALRM    14

Timer signal.

SIGTERM    15

Termination signal.

SIGSTKFLT    16

Coprocessor stack error.

SIGCHLD    17

Child process terminated or stopped.

SIGCONT    18

Resumes a suspended process.

SIGSTOP    19

Suspends a process.

SIGTSTP    20

Stops a process by entering the command on the terminal.

SIGTTIN    21

Input required by the background process.

SIGTTOU    22

Output required by the background process.

SIGURG    23

Urgent socket condition.

SIGXCPU    24

CPU time limit exceeded.

SIGXFSZ    25

File size limit exceeded.

SIGVTALRM    26

Virtual timer, used to calculate the CPU occupation time of a process.

SIGPROF    27

Calculates the CPU time occupied by a process and the system calling time.

SIGWINCH    28

Window size change.

SIGIO    29

Input/Output.

SIGPOLL    SIGIO

Equivalent to SIGIO.

SIGPWR    30

Power failure.

SIGSYS    31

Non-existent system call.

SIGUNUSED    31

Equivalent to SIGSYS.

SIGRTMIN   32

Start of a reliable signal.

SIGRTMIN   (libc_current_sigrtmin())

Start of a reliable signal.

SIGRTMAX   _NSIG

End of a reliable signal.

SIGRTMAX   (libc_current_sigrtmax())

End of a reliable signal.

SA_THIRTYTWO    0x02000000

Transfers signals in a 32-bit mode even if the task runs in a 26-bit mode.

SA_NOMASK    SA_NODEFER

Signals being processed are not masked during signal processing.

SA_ONESHOT    SA_RESETHAND

The default processing mode is restored after the signal processing is complete.

SIG_BLOCK    0

Defines the function behaviors such as sigprocmask() and pthread_sigmask(), which are used to add signals to the mask set.

SIG_UNBLOCK    1

Defines the function behaviors such as sigprocmask() and pthread_sigmask(), which are used to remove signals from the mask set.

SIG_SETMASK    2

Defines the function behaviors such as sigprocmask() and pthread_sigmask(), which are used to set the mask set.

sa_handler   _u._sa_handler

Defines the simplified writing used to indicate the sa_handler.sa_handler field in sigaction.

sa_handler   sa_handler.sa_handler

Defines the simplified writing used to indicate the sa_handler.sa_handler field in sigaction.

sa_sigaction   _u._sa_sigaction

Defines the simplified writing used to indicate the sa_handler.sa_sigaction field in sigaction.

sa_sigaction   sa_handler.sa_sigaction

Defines the simplified writing used to indicate the __sa_handler.sa_sigaction field in sigaction.

SIG_HOLD    ((void ()(int)) 2)

Defines the function behaviors such as sigset() and adds a specified signal to the process signal mask without changing the current processing mode of the signal.

SIGEV_SIGNAL    0

Sets the notification method in sigevent: signal notification.

SIGEV_NONE    1

Sets the notification method in sigevent: no notification.

SIGEV_THREAD    2

Sets the notification method in sigevent: thread notification.

SIG_ERR    ((sighandler_t)-1)

Defines the value returned when a function such as signal() fails.

SIG_DFL    ((sighandler_t)0)

Defines the default signal processing mode.

SIG_IGN    ((__sighandler_t)1)

Defines the signal processing mode in which the signal is ignored.

IPC_CREAT    01000

Defines the input parameter used to create an IPC object.

IPC_EXCL    02000

Defines the input parameter used together with IPC_CREAT to prevent duplicate key values during IPC creation.

IPC_NOWAIT    04000

Defines the input parameter that specifies whether the communication is in non-blocking mode.

IPC_RMID    0

Defines the input parameter used to delete an IPC object.

IPC_SET    1

Defines the input parameter used to set information to the kernel.

IPC_INFO    3

Defines the input parameter used to obtain the system-level restriction information of a specified communication type, for example, shminfo.

IPC_PRIVATE    ((key_t) 0)

Defines the IPC object as a private object.

Typedefs

Typedef Name

Description

ucontext_t

typedef struct __ucontext 

Describes the user execution context.

stack_t

typedef struct sigaltstack 

Describes a signal stack.

sighandler_t ) (int)

typedef void(* 

Function pointer of signal handler.

Functions

Function Name

Description

mq_close (mqd_t mqdes)

int 

Closes a message queue that is no longer used.

mq_getattr (mqd_t mqdes, struct mq_attr attr)

int 

Obtains the attributes of the message queue specified by the descriptor. The values of mq_maxmsg, mq_msgsize, and mq_curmsgs are fixed.

mq_open (const char name, int oflag,…)

mqd_t 

Creates a message queue or opens an existing message queue.

mq_receive (mqd_t mqdes, char buffer, size_t size, unsigned prioptr)

ssize_t 

Receives a message from a specified message queue.

mq_send (mqd_t mqdes, const char buffer, size_t size, unsigned prio)

int 

Sends a message to a specified message queue.

mq_setattr (mqd_t mqdes, const struct mq_attr restrict newattr, struct mq_attr *restrict oldattr)

int 

Sets the attributes of the message queue specified by the descriptor. The mq_maxmsg, mq_msgsize, and mq_curmsgs attributes cannot be modified. mq_flags supports the O_NONBLOCK attribute only.

mq_timedreceive (mqd_t mqdes, char __restrict buffer, size_t size, unsigned restrict prioptr, const struct timespec *restrict timeout)

ssize_t 

Receives a message from the message queue, with a timeout period specified.

mq_timedsend (mqd_t mqdes, const char buffer, size_t size, unsigned prio, const struct timespec timeout)

int 

Sends a message to a specified message queue, with a timeout period specified.

mq_unlink (const char name)

int 

Decreases the reference count of the message queue by 1, or deletes the message queue if the reference count is 0.

sem_close (sem_t sem)

int 

Closes a specified semaphore.

sem_destroy (sem_t sem)

int 

Destroys a specified anonymous semaphore that is no longer used.

sem_getvalue (sem_t restrict sem, int *restrict sval)

int 

Obtains the count value of a specified semaphore.

sem_init (sem_t sem, int pshared, unsigned int value)

int 

Creates and initializes an anonymous semaphore.

sem_post (sem_t sem)

int 

Increments the semaphore count by 1.

sem_timedwait (sem_t __restrict sem, const struct timespec restrict timeout)

int 

Obtains the semaphore, with a timeout period specified.

sem_trywait (sem_t sem)

int 

Attempts to obtain the semaphore.

sem_unlink (const char name)

int 

Deletes a specified semaphore.

sem_wait (sem_t sem)

int 

Obtains the semaphore.

kill (pid_t pid, int sig)

int 

Sends a signal to a specified process.

sigemptyset (sigset_t set)

int 

Clears all signals in a specified signal set.

sigfillset (sigset_t set)

int 

Adds all signals to a specified signal set.

sigaddset (sigset_t set, int signum)

int 

Adds a signal to a specified signal set.

sigdelset (sigset_t set, int signum)

int 

Delete a signal from a specified signal set.

sigismember (const sigset_t set, int signum)

int 

Checks whether a signal is in the signal set.

sigprocmask (int how, const sigset_t *restrict set, sigset_t __restrict oldset)

int 

Changes the signal mask of the calling thread.

sigsuspend (const sigset_t mask)

int 

Sets mask as the signal mask set of the current process and suspends the process until a signal processing action is triggered.

sigaction (int signum, const struct sigaction __restrict act, struct sigaction restrict oldact)

int 

Checks or changes the processing action associated with a specified signal. Do not use the process creation function or thread creation function in the registered callback processing function. Otherwise, the process is abnormal. For example, do not use the fork or pthread_create function.

sigpending (sigset_t set)

int 

Obtains the signal suspended by the current thread.

sigwait (const sigset_t restrict set, int __restrict sig)

int 

Suspends the calling thread and waits for the signal.

sigwaitinfo (const sigset_t restrict set, siginfo_t *restrict info)

int 

Suspends the calling thread and waits for the signal, with a timeout period specified.

sigtimedwait (const sigset_t __restrict set, siginfo_t restrict info, const struct timespec *restrict timeout)

int 

Suspends the calling thread and waits for the signal, with a timeout period specified.

pthread_sigmask (int how, const sigset_t __restrict set, sigset_t __restrict oldset)

int 

Checks or changes the signal mask of the calling thread.

psignal (int signum, const char s)

void 

Prints signal information.

sigpause (int signum)

int 

Deletes the signal specified by signum from the signal mask of the calling process and suspends the process until the signal is received.

sighold (int signum)

int 

Adds the signal specified by signum to the signal mask of the calling process.

sigrelse (int signum)

int 

Deletes the signal specified by signum from the signal mask of the calling process.

sigisemptyset (const sigset_t set)

int 

Checks whether the signal set is empty.

sigorset (sigset_t dest, const sigset_t left, const sigset_t right)

int 

Adds the union set of left and right to dest.

sigandset (sigset_t dest, const sigset_t left, const sigset_t right)

int 

Adds the intersection of left and right to dest.

signal (int signum, sighandler_t handler)

sighandler_t 

Changes the processing action of a specified signal. Do not use the process creation function or thread creation function in the registered callback processing function. Otherwise, the process is abnormal. For example, do not use the fork or pthread_create function.

raise (int signum)

int 

Sends a signal to the calling process.

Details

Macro Definition Documentation

MINSIGSTKSZ [1/2]

  1. #define MINSIGSTKSZ 2048

Description:

Defines the minimum size of the replaceable signal stack.

Minimum size of the replaceable signal stack.

MINSIGSTKSZ [2/2]

  1. #define MINSIGSTKSZ 2048

Description:

Defines the minimum size of the replaceable signal stack.

Minimum size of the replaceable signal stack.

sa_handler [1/2]

  1. #define sa_handler _u._sa_handler

Description:

Defines the simplified writing used to indicate the __sa_handler.sa_handler field in sigaction.

Indicates the _u._sa_handler field in sigaction.

sa_handler [2/2]

  1. #define sa_handler __sa_handler.sa_handler

Description:

Defines the simplified writing used to indicate the __sa_handler.sa_handler field in sigaction.

Indicates the _u._sa_handler field in sigaction.

SA_NOCLDSTOP [1/2]

  1. #define SA_NOCLDSTOP 1

Description:

Stops a child process without sending the SIGCHLD signal.

SIGCHLD is not generated when the child process is stopped.

SA_NOCLDSTOP [2/2]

  1. #define SA_NOCLDSTOP 0x00000001

Description:

Stops a child process without sending the SIGCHLD signal.

SIGCHLD is not generated when the child process is stopped.

SA_NODEFER [1/2]

  1. #define SA_NODEFER 0x40000000

Description:

The signals being processed are not masked during signal processing.

Signals being processed are not masked during signal processing.

SA_NODEFER [2/2]

  1. #define SA_NODEFER 0x40000000

Description:

The signals being processed are not masked during signal processing.

Signals being processed are not masked during signal processing.

SA_ONSTACK [1/2]

  1. #define SA_ONSTACK 0x08000000

Description:

Uses the signal stack specified by sigaltstack for signal processing.

The signal stack specified by sigaltstack is used for signal processing.

SA_ONSTACK [2/2]

  1. #define SA_ONSTACK 0x08000000

Description:

Uses the signal stack specified by sigaltstack for signal processing.

The signal stack specified by sigaltstack is used for signal processing.

sa_sigaction [1/2]

  1. #define sa_sigaction _u._sa_sigaction

Description:

Defines the simplified writing used to indicate the __sa_handler.sa_sigaction field in sigaction.

Indicates the __sa_handler.sa_sigaction field in sigaction.

sa_sigaction [2/2]

  1. #define sa_sigaction __sa_handler.sa_sigaction

Description:

Defines the simplified writing used to indicate the __sa_handler.sa_sigaction field in sigaction.

Indicates the __sa_handler.sa_sigaction field in sigaction.

SA_SIGINFO [1/2]

  1. #define SA_SIGINFO 4

Description:

Transfers the siginfo_t structure with the signal.

Transfers the siginfo_t with the signal.

SA_SIGINFO [2/2]

  1. #define SA_SIGINFO 0x00000004

Description:

Transfers the siginfo_t structure with the signal.

Transfers the siginfo_t with the signal.

SIGRTMAX [1/2]

  1. #define SIGRTMAX [_NSIG]($api-api-SmartVision-Devices-IPC.md#ga275020780cb70a8b0cba8db5accc5d19)

Description:

End of a reliable signal.

Defines the highest available signal number.

SIGRTMAX [2/2]

  1. #define SIGRTMAX (__libc_current_sigrtmax())

Description:

End of a reliable signal.

Defines the highest available signal number.

SIGRTMIN [1/2]

  1. #define SIGRTMIN 32

Description:

Start of a reliable signal.

Defines the lowest available signal number.

SIGRTMIN [2/2]

  1. #define SIGRTMIN (__libc_current_sigrtmin())

Description:

Start of a reliable signal.

Defines the lowest available signal number.

SIGSTKSZ [1/2]

  1. #define SIGSTKSZ 8192

Description:

Defines the size of a signal stack.

Size of a signal stack.

SIGSTKSZ [2/2]

  1. #define SIGSTKSZ 8192

Description:

Defines the size of a signal stack.

Size of a signal stack.

Typedef Documentation

stack_t

  1. typedef struct [sigaltstack]($api-api-SmartVision-Devices-sigaltstack.md) [stack_t]($api-api-SmartVision-Devices-IPC.md#ga395f9ff4025fe05bb535322593abde72)

Description:

Describes a signal stack.

Describes stack information for signal processing.

Function Documentation

kill()

  1. int kill (pid_t pid, int sig )

Description:

Sends a signal to a specified process.

Parameters:

Name

Description

pid Indicates the target process ID. Parameters 0 and -1 are not supported.
sig Indicates the signal to be sent.

Attention:

The default signal behavior does not support STOP and CONTINUE, and COREDUMP is not involved. SIGSTOP, SIGKILL, and SIGCONT cannot be masked. If a process is killed but its parent process is not recycled, a zombie process will be generated. After an asynchronous signal is sent to a process, the signal callback is executed only after the process is scheduled. The kernel cannot forcibly kill the process by using the signal. After the process is killed, SIGCHLD is sent to its parent process. The sending action cannot be canceled. A sleeping process cannot be woken up by a signal. For example, a process invokes the sleep function to enter the sleeping state. Currently, suspended and zombie processes cannot be forcibly killed.

Returns:

Returns 0 if the operation is successful; returns -1 and sets errno to a value in the following table if the operation fails.

errno

Description

EINVAL

sig is invalid.

EPERM

The current process does not have permission to send the signal to the target process.

mq_close()

  1. int mq_close (mqd_t mqdes)

Description:

Closes a message queue that is no longer used.

Parameters:

Name

Description

mqdes Indicates the descriptor of the message queue to be closed.

Returns:

Returns 0 if the message queue is closed; returns -1 and sets errno to a value in the following table if the message queue fails to be closed.

errno

Description

EBADF

mqdes is invalid.

EAGAIN

Failed to delete the message queue in the function.

EFAULT

Failed to release the space allocated with the message queue.

EINVAL

mqdes is invalid when the message queue is deleted in the function.

mq_getattr()

  1. int mq_getattr (mqd_t mqdes, struct [mq_attr]($api-api-SmartVision-Devices-mq_attr.md) * attr )

Description:

Obtains the attributes of the message queue specified by the descriptor. The values of mq_maxmsg, mq_msgsize, and mq_curmsgs are fixed.

Parameters:

Name

Description

mqdes Indicates the message queue descriptor.
attr Indicates the pointer to the obtained message queue attributes.

Returns:

Returns 0 if the operation is successful; returns -1 and sets errno to a value in the following table if the operation fails.

errno

Description

EBADF

mqdes is invalid.

EINVAL

attr is NULL.

mq_open()

  1. mqd_t mq_open (const char * name, int oflag, ... )

Description:

Creates a message queue or opens an existing message queue.

Parameters:

Name

Description

name Indicates the name of the message queue to be created or opened. The maximum value is 259 bytes.
oflag Indicates the open flag, including O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, and O_NONBLOCK.
mode Used for permission control (not supported currently). Its type is mode_t. This is parameter is required only during the creation of a message queue.
attr Indicates the pointer to the queue attributes to be set. Its type is struct mq_attr. This parameter is optional and is used only during the creation of a message queue.

Attention:

The message consists of 64 bytes by default, and the maximum length of the message is 64 KB. A maximum of 1024 message queues can be created. The mq_curmsgs field in mq_attr is not supported.

Returns:

Returns a message queue descriptor if the creation or opening is successful; returns (mqd_t)-1 and sets errno to a value in the following table if the operation fails.

errno

Description

EEXIST

Both O_CREAT and O_EXCL are specified in oflag, and a queue with this name already exists.

EINVAL

O_CREAT is specified in oflag, and attr is invalid. To be specific, the attribute value of the mq_maxmsg field is less than 0 or greater than USHRT_MAX, or the attribute value of mq_msgsize is less than 0 or greater than USHRT_MAX-4. name is NULL, or the length of the string specified by name is 0.

ENAMETOOLONG

name is too long.

ENOENT

O_CREAT is not specified in oflag, and no queue with this name exists.

ENOSPC

Insufficient memory.

ENFILE

The number of opened message queues exceeds the maximum.

mq_receive()

  1. ssize_t mq_receive (mqd_t mqdes, char * buffer, size_t size, unsigned * prioptr )

Description:

Receives a message from a specified message queue.

The message queue must have been open by mq_open().

Parameters:

Name

Description

mqdes Indicates the message queue descriptor.
buffer Indicates the pointer to the buffer for receiving the message.
size Indicates the size of the buffer for receiving the message.
prioptr Indicates the priority of the received message if the value is not NULL. This parameter is not used because priority-based message processing is not supported.

Returns:

Returns the number of bytes in the received message if the message is received; returns (mqd_t)-1 and sets errno to a value in the following table if the message fails to be received.

errno

Description

EINTR

Message receiving is interrupted.

EAGAIN

The message queue is empty, and O_NONBLOCK is set for the message queue associated with mqdes.

EBADF

mqdes is invalid or you do not have the read permission.

EMSGSIZE

The size of the buffer for receiving the message is less than the message size attribute of the message queue.

EINVAL

mqdes is NULL or the value of size is 0.

mq_send()

  1. int mq_send (mqd_t mqdes, const char * buffer, size_t size, unsigned prio )

Description:

Sends a message to a specified message queue.

The message queue must have been opened using mq_open().

Parameters:

Name

Description

mqdes Indicates the message queue descriptor.
buffer Indicates the pointer to the buffer for receiving the message.
size Indicates the size of the buffer for receiving the message.
prio Indicates the priority of the message to be sent. This parameter must be 0 because priority-based message processing is not supported.

Returns:

Returns 0 if the message is sent; returns -1 and sets errno to a value in the following table if the message fails to be sent.

errno

Description

EINTR

Message sending is interrupted.

EAGAIN

The message queue is full, and O_NONBLOCK is set for the message queue associated with mqdes.

EBADF

mqdes is invalid or you do not have the write permission.

EINVAL

mqdes is NULL or the value of size is 0.

EMSGSIZE

The size of the message to be sent is greater than the message size attribute of the message queue.

EOPNOTSUPP

The operation is not supported.

ENOSPC

Insufficient space.

mq_setattr()

  1. int mq_setattr (mqd_t mqdes, const struct [mq_attr]($api-api-SmartVision-Devices-mq_attr.md) *__restrict newattr, struct [mq_attr]($api-api-SmartVision-Devices-mq_attr.md) *__restrict oldattr )

Description:

Sets the attributes of the message queue specified by the descriptor. The mq_maxmsg, mq_msgsize, and mq_curmsgs attributes cannot be modified. mq_flags supports the O_NONBLOCK attribute only.

The message queue must have been opened using mq_open().

Parameters:

Name

Description

mqdes Indicates the message queue descriptor.
newattr Indicates the pointer to the message queue attribute to be set.
oldattr Indicates the pointer to the original attribute.

Returns:

Returns 0 if the setting is successful; returns -1 and sets errno to a value in the following table if the setting fails.

errno

Description

EBADF

mqdes is invalid.

EINVAL

newattr is NULL.

mq_timedreceive()

  1. ssize_t mq_timedreceive (mqd_t mqdes, char *__restrict buffer, size_t size, unsigned *__restrict prioptr, const struct [timespec]($api-api-SmartVision-Devices-timespec.md) *__restrict timeout )

Description:

Receives a message from the message queue, with a timeout period specified.

The message queue must have been open by mq_open().

Parameters:

Name

Description

mqdes Indicates the message queue descriptor.
buffer Indicates the pointer to the buffer for receiving the message.
size Indicates the size of the buffer for receiving the message.
prioptr Indicates the priority of the received message if the value is not NULL. This parameter is not used because priority-based message processing is not supported.
timeout Indicates the timeout duration for returning a request.

Returns:

Returns the number of bytes in the message if the message is received; returns (mqd_t)-1 and sets errno to a value in the following table if the message fails to be received.

errno

Description

EINTR

Message receiving is interrupted.

EAGAIN

The message queue is empty, and O_NONBLOCK is set for the message queue associated with mqdes.

EBADF

mqdes is invalid or you do not have the read permission.

EINVAL

mqdes is NULL or the value of size is 0. timeout is invalid. Specifically, the value of tv_sec is less than 0, and the value of tv_nsec is less than 0 or greater than the ninth power of 10.

EMSGSIZE

The size of the buffer for receiving the message is less than the message size attribute of the message queue.

ETIMEDOUT

No message is received from the queue before the specified timeout period expires.

mq_timedsend()

  1. int mq_timedsend (mqd_t mqdes, const char * buffer, size_t size, unsigned prio, const struct [timespec]($api-api-SmartVision-Devices-timespec.md) * timeout )

Description:

Sends a message to a specified message queue, with a timeout period specified.

The message queue must have been open by mq_open().

Parameters:

Name

Description

mqdes Indicates the message queue descriptor.
buffer Indicates the pointer to the buffer for sending the message.
size Indicates the size of the message to be sent.
prio Indicates the priority of the message to be sent. This parameter must be 0 because priority-based message processing is not supported.
timeout Indicates the timeout duration for returning a request.

Returns:

Returns 0 if the message is sent; returns -1 and sets errno to a value in the following table if the message fails to be sent.

errno

Description

EINTR

Message sending is interrupted.

EAGAIN

The message queue is full, and O_NONBLOCK is set for the message queue associated with mqdes.

EBADF

mqdes is invalid or you do not have the write permission.

EINVAL

mqdes is NULL or the value of size is 0. timeout is invalid. Specifically, the value of tv_sec is less than 0, and the value of tv_nsec is less than 0 or greater than the ninth power of 10.

EMSGSIZE

The size of the message to be sent is greater than the message size attribute of the message queue.

EOPNOTSUPP

The operation is not supported.

ETIMEDOUT

No message is sent to the queue before the specified timeout period expires.

mq_unlink()

  1. int mq_unlink (const char * name)

Description:

Decreases the reference count of the message queue by 1, or deletes the message queue if the reference count is 0.

Parameters:

Name

Description

name Indicates the message queue name.

Returns:

Returns 0 if the operation is successful; returns -1 and sets errno to a value in the following table if the operation fails.

errno

Description

ENAMETOOLONG

name is too long.

ENOENT

There is no message queue with the given name.

EAGAIN

Failed to delete the message queue.

EBUSY

The message queue to be deleted is being used.

EINVAL

name is NULL, or the length of the string specified by name is 0.

psignal()

  1. void psignal (int signum, const char * s )

Description:

Prints signal information.

This function is used to print a message on the standard error output. The message consists of the character string s, a colon, a space, a string describing the signal information signum, and a newline character. If the string s is NULL or empty, the colon and space are omitted. If signum is invalid, the message displayed will indicate an unknown signal.

Parameters:

Name

Description

signum Indicates the signal to be operated.
s Indicates the customized string s to be printed.

pthread_sigmask()

  1. int pthread_sigmask (int how, const sigset_t *__restrict set, sigset_t *__restrict oldset )

Description:

Checks or changes the signal mask of the calling thread.

Parameters:

Name

Description

how Indicates the function behavior.
set Indicates the signal set to be changed.
oldset Used for returning the original mask set of the calling thread.

flags

Description

SIG_BLOCK

Adds the signals in set to the mask set of the thread.

SIG_UNBLOCK

Removes the signals in set from the mask set of the thread.

SIG_SETMASK

Sets set of blocked signals as the mask set of the thread.

Returns:

Returns 0 if the change is successful; returns errno as described below if the change fails.

errno

Description

EINVAL

how is invalid.

EFAULT

The set or oldset points outside the process’s allocated address space.

raise()

  1. int raise (int signum)

Description:

Sends a signal to the calling process.

Parameters:

Name

Description

signum Indicates the signal to be sent.

Returns:

Returns 0 if the operation is successful; returns nonzero if the operation fails.

sem_close()

  1. int sem_close ([sem_t]($api-api-SmartVision-Devices-sem_t.md) * sem)

Description:

Closes a specified semaphore.

Parameters:

Name

Description

sem Indicates the pointer to the semaphore to close.

Returns:

Returns 0 if the semaphore is closed. errno | Description

sem_destroy()

  1. int sem_destroy ([sem_t]($api-api-SmartVision-Devices-sem_t.md) * sem)

Description:

Destroys a specified anonymous semaphore that is no longer used.

Parameters:

Name

Description

sem Indicates the pointer to the semaphore to destroy.

Returns:

Returns 0 if the destruction is successful.

sem_getvalue()

  1. int sem_getvalue ([sem_t]($api-api-SmartVision-Devices-sem_t.md) *__restrict sem, int *__restrict sval )

Description:

Obtains the count value of a specified semaphore.

Parameters:

Name

Description

sem Indicates the pointer to the semaphore.
sval Indicates the pointer to the obtained count value.

Returns:

Returns 0 if the operation is successful.

sem_init()

  1. int sem_init ([sem_t]($api-api-SmartVision-Devices-sem_t.md) * sem, int pshared, unsigned int value )

Description:

Creates and initializes an anonymous semaphore.

Parameters:

Name

Description

sem Indicates the pointer to the semaphore to be created or initialized.
pshared Specifies whether the semaphore can be shared between the threads of a process. 0 indicates that the semaphore is shared between the threads of a process. A non-zero value indicates that the semaphore can be shared between processes.
value Indicates the initial count value of the new semaphore.

Returns:

Returns 0 if the initialization is successful; returns -1 and sets errno to a value in the following table if the initialization fails.

errno

Description

EINVAL

The input parameters are invalid and the initial count value exceeds the limit.

sem_post()

  1. int sem_post ([sem_t]($api-api-SmartVision-Devices-sem_t.md) * sem)

Description:

Increments the semaphore count by 1.

Generally, this function is used to increment the count of available shared resources when the process is to leave its critical section. This function is used together with sem_wait() to protect shared resources.

Parameters:

Name

Description

sem Indicates the pointer to the semaphore to be operated.

Returns:

Returns 0 if the operation is successful; returns -1 and sets errno to a value in the following table if the operation fails.

errno

Description

EOVERFLOW

The number of semaphores exceeds the maximum number.

sem_timedwait()

  1. int sem_timedwait ([sem_t]($api-api-SmartVision-Devices-sem_t.md) *__restrict sem, const struct [timespec]($api-api-SmartVision-Devices-timespec.md) *__restrict timeout )

Description:

Obtains the semaphore, with a timeout period specified.

If the semaphore count is greater than 0, the shared resources can be obtained and the semaphore count decreases by 1. After the function returns 0, the code execution enters the resource critical area. Otherwise, the shared resource is unavailable, the function keeps waiting, and code execution cannot enter the resource critical area. If no semaphore is obtained within the specified timeout period, -1 is returned. This function is used together with sem_post() to protect shared resources.

Parameters:

Name

Description

sem Indicates the pointer to the semaphore to be operated.
timeout Indicates the timeout period to be set.

Returns:

Returns 0 if the semaphore is obtained; returns -1 and sets errno to a value in the following table if the semaphore fails to be obtained.

errno

Description

EINVAL

sem or timeout is invalid.

EINTR

The waiting for the semaphore is interrupted.

EAGAIN

The semaphore is set to non-blocking mode, and the semaphore count is 0.

ETIMEDOUT

Waiting for the semaphore timed out.

sem_trywait()

  1. int sem_trywait ([sem_t]($api-api-SmartVision-Devices-sem_t.md) * sem)

Description:

Attempts to obtain the semaphore.

If the semaphore count is greater than 0, the shared resources can be obtained and the semaphore count decreases by 1. After the function returns 0, the code execution enters the resource critical area. Otherwise, the shared resource is unavailable, and the function returns -1. This function is used together with sem_post() to protect shared resources.

Parameters:

Name

Description

sem Indicates the pointer to the semaphore to be operated.

Returns:

Returns 0 if the semaphore is obtained; returns -1 and sets errno to a value in the following table if the semaphore fails to be obtained.

errno

Description

EINVAL

sem is invalid.

EAGAIN

The semaphore is set to non-blocking mode, and the semaphore count is 0.

sem_unlink()

  1. int sem_unlink (const char * name)

Description:

Deletes a specified semaphore.

This function is used to subtract 1 from the open count of the semaphore. If the open count is 0, this function deletes the semaphore.

Parameters:

Name

Description

name Indicates the name of the semaphore to be deleted.

Returns:

Returns 0 if the operation is successful; returns -1 and sets errno to a value in the following table if the operation fails.

errno

Description

ENAMETOOLONG

name is too long.

ENOENT

There is no semaphore with the given name.

sem_wait()

  1. int sem_wait ([sem_t]($api-api-SmartVision-Devices-sem_t.md) * sem)

Description:

Obtains the semaphore.

If the semaphore count is greater than 0, the shared resources can be obtained and the semaphore count decreases by 1. After the function returns 0, the code execution enters the resource critical area. Otherwise, the shared resource is unavailable, the function keeps waiting, and code execution cannot enter the resource critical area. This function is used together with sem_post() to protect shared resources.

Parameters:

Name

Description

sem Indicates the pointer to the semaphore to be obtained.

Returns:

Returns 0 if the semaphore is obtained; returns -1 and sets errno to a value in the following table if the semaphore fails to be obtained.

errno

Description

EINVAL

sem is invalid.

EINTR

The waiting for the semaphore is interrupted.

EAGAIN

The semaphore is set to non-blocking mode, and the semaphore count is 0.

sigaction()

  1. int [sigaction]($api-api-SmartVision-Devices-sigaction.md) (int signum, const struct [sigaction]($api-api-SmartVision-Devices-sigaction.md) *__restrict act, struct [sigaction]($api-api-SmartVision-Devices-sigaction.md) *__restrict oldact )

Description:

Checks or changes the processing action associated with a specified signal. Do not use the process creation function or thread creation function in the registered callback processing function. Otherwise, the process is abnormal. For example, do not use the fork or pthread_create function.

Parameters:

Name

Description

signum Indicates the signal to be operated.
act Indicates the new signal processing action.
oldact Indicates the original signal processing action if the value is not NULL.

Attention:

The sa_flag field in act supports the SA_SIGINFO flag only.

Returns:

Returns 0 if the operation is successful; returns -1 and sets errno to a value in the following table if the operation fails.

errno

Description

EINVAL

signum is invalid or cannot be captured.

act is NULL.

ENOMEM

Insufficient memory.

sigaddset()

  1. int sigaddset (sigset_t * set, int signum )

Description:

Adds a signal to a specified signal set.

Parameters:

Name

Description

set Indicates the pointer to the signal set to hold signals.
signum Indicates the signal to be added.

Returns:

Returns 0 if the operation is successful. If set or signum is invalid, the process is abnormal.

sigandset()

  1. int sigandset (sigset_t * dest, const sigset_t * left, const sigset_t * right )

Description:

Adds the intersection of left and right to dest.

Parameters:

Name

Description

dest Indicates the pointer to the target signal set.
left Indicates the left set to be added.
right Indicates the right set to be added.

Returns:

Returns 0 if the operation is successful.

sigdelset()

  1. int sigdelset (sigset_t * set, int signum )

Description:

Delete a signal from a specified signal set.

Parameters:

Name

Description

set Indicates the pointer to the signal set to hold signals.
signum Indicates the signal to be deleted.

Returns:

Returns 0 if the operation is successful. If set or signum is invalid, the process is abnormal.

sigemptyset()

  1. int sigemptyset (sigset_t * set)

Description:

Clears all signals in a specified signal set.

Parameters:

Name

Description

set Indicates the pointer to the signal set to be cleared.

Returns:

Returns 0 if the operation is successful. If set is invalid, the process is abnormal.

sigfillset()

  1. int sigfillset (sigset_t * set)

Description:

Adds all signals to a specified signal set.

Parameters:

Name

Description

set Indicates the pointer to the signal set to hold signals.

Returns:

Returns 0 if the operation is successful. If set is invalid, the process is abnormal.

sighold()

  1. int sighold (int signum)

Description:

Adds the signal specified by signum to the signal mask of the calling process.

Parameters:

Name

Description

signum Indicates the signal to be added.

Returns:

Returns 0 if the operation is successful; returns -1 if the operation fails.

sigisemptyset()

  1. int sigisemptyset (const sigset_t * set)

Description:

Checks whether the signal set is empty.

Parameters:

Name

Description

set Indicates the pointer to the signal set to be checked.

Returns:

Returns 0 if the set is not empty; returns 1 if the set is empty; returns -1 if the operation fails.

sigismember()

  1. int sigismember (const sigset_t * set, int signum )

Description:

Checks whether a signal is in the signal set.

Parameters:

Name

Description

set Indicates the pointer to the signal set to be checked.
signum Indicates the signal to be checked.

Returns:

Returns 0 if the signal is not in the set; returns 1 if the signal is in the set. If set or signum is invalid, the process is abnormal.

signal()

  1. [sighandler_t]($api-api-SmartVision-Devices-IPC.md#ga754cdc0bcfffe07baa426dc252c9101a) signal (int signum, [sighandler_t]($api-api-SmartVision-Devices-IPC.md#ga754cdc0bcfffe07baa426dc252c9101a) handler )

Description:

Changes the processing action of a specified signal. Do not use the process creation function or thread creation function in the registered callback processing function. Otherwise, the process is abnormal. For example, do not use the fork or pthread_create function.

Parameters:

Name

Description

signum Indicates the signal to be operated.
handler Indicates the pointer to the specified processing action (SIG_IGN or SIG_DFL, or to a custom processing action.

Returns:

Returns the pointer to the original processing action if the operation is successful; returns SIG_ERR and sets errno to a value in the following table if the operation fails.

errno

Description

EINVAL

signum is invalid.

ENOMEM

Insufficient memory.

sigorset()

  1. int sigorset (sigset_t * dest, const sigset_t * left, const sigset_t * right )

Description:

Adds the union set of left and right to dest.

Parameters:

Name

Description

dest Indicates the pointer to the target signal set.
left Indicates the left set to be added.
right Indicates the right set to be added.

Returns:

Returns 0 if the operation is successful.

sigpause()

  1. int sigpause (int signum)

Description:

Deletes the signal specified by signum from the signal mask of the calling process and suspends the process until the signal is received.

Parameters:

Name

Description

signum Indicates the signal to be operated.

Attention:

After the signal is received, the original signal mask of the process is restored.

Returns:

Returns -1 and sets errno to a value in the following table.

errno

Description

EINTR

The suspension wait is interrupted by the signal.

sigpending()

  1. int sigpending (sigset_t * set)

Description:

Obtains the signal suspended by the current thread.

Parameters:

Name

Description

set Indicates the pointer to the signal set used to store the signal suspended by the current thread.

Returns:

Returns 0 if the operation is successful; returns -1 and sets errno to a value in the following table if the operation fails.

errno

Description

EFAULT

set points to an invalid space.

EINVAL

set is NULL.

EINTR

The suspension wait is interrupted by the signal.

sigprocmask()

  1. int sigprocmask (int how, const sigset_t *__restrict set, sigset_t *__restrict oldset )

Description:

Changes the signal mask of the calling thread.

Parameters:

Name

Description

how Indicates the function behavior.
set Indicates the pointer to the signal set to be changed.
oldset Indicates the pointer to the original mask set of the calling thread.

flags

Description

SIG_BLOCK

Adds the signals in set to the mask set of the thread.

SIG_UNBLOCK

Removes the signals in set from the mask set of the thread.

SIG_SETMASK

Sets set of blocked signals as the mask set of the thread.

Returns:

Returns 0 if the change is successful; returns -1 and sets errno to a value in the following table if the change fails.

errno

Description

EINVAL

how is invalid.

EFAULT

The set or oldset points outside the process’s allocated address space.

sigrelse()

  1. int sigrelse (int signum)

Description:

Deletes the signal specified by signum from the signal mask of the calling process.

Parameters:

Name

Description

signum Indicates the signal to be deleted.

Returns:

Returns 0 if the deletion is successful; returns -1 if the deletion fails.

sigsuspend()

  1. int sigsuspend (const sigset_t * mask)

Description:

Sets mask as the signal mask set of the current process and suspends the process until a signal processing action is triggered.

Parameters:

Name

Description

mask Indicates the pointer to the signal set to be set.

Returns:

Returns -1 and sets errno to a value in the following table.

errno

Description

EFAULT

mask points to an invalid space.

EINTR

The suspension wait is interrupted by the signal.

EINVAL

mask is NULL.

sigtimedwait()

  1. int sigtimedwait (const sigset_t *__restrict set, siginfo_t *__restrict info, const struct [timespec]($api-api-SmartVision-Devices-timespec.md) *__restrict timeout )

Description:

Suspends the calling thread and waits for the signal, with a timeout period specified.

This function is used to suspend execution of the calling thread until one of the signals specified in the signal set becomes pending. This function specifies the timeout behavior.

Parameters:

Name

Description

set Indicates the pointer to the signal set to be waited.
info Used to save the information about the waited signal if the value is not NULL.
timeout Indicates the timeout duration.

Attention:

The signal to be waited must be in the mask set of the current thread. Once the signal is received, it is deleted from the pending list. The waiting for the signal cannot be interrupted by other signals, that is, EINTR is not supported.

Returns:

Returns the value of the waited signal if the operation is successful; returns -1 and sets errno to a value in the following table if the operation fails.

errno

Description

EAGAIN

No signal specified by set is generated within the specified timeout period.

EINVAL

timeout is invalid.

sigwait()

  1. int sigwait (const sigset_t *__restrict set, int *__restrict sig )

Description:

Suspends the calling thread and waits for the signal.

This function is used to suspend execution of the calling thread until one of the signals specified in the signal set becomes pending.

Parameters:

Name

Description

set Indicates the pointer to the signal set to be waited.
sig Used for saving the waited signal.

Attention:

The signal to be waited must be in the mask set of the current thread. Once the signal is received, it is deleted from the pending list.

Returns:

Returns 0 if the signal is received; returns -1 and sets errno to a value in the following table if the signal fails to be received.

errno

Description

EINTR

The suspension wait is interrupted by the signal.

sigwaitinfo()

  1. int sigwaitinfo (const sigset_t *__restrict set, siginfo_t *__restrict info )

Description:

Suspends the calling thread and waits for the signal, with a timeout period specified.

This function is used to suspend execution of the calling thread until one of the signals specified in the signal set becomes pending. This function does not specify the timeout behavior.

Parameters:

Name

Description

set Indicates the pointer to the signal set to be waited.
info Used to save the information about the waited signal if the value is not NULL.

Attention:

The signal to be waited must be in the mask set of the current thread. Once the signal is received, it is deleted from the pending list. The waiting for the signal cannot be interrupted by other signals, that is, EINTR is not supported.

Returns:

Returns the value of the waited signal if the operation is successful; returns -1 and sets errno to a value in the following table if the operation fails. errno | Description ———|——————————————-—