HP C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index


sigsuspend

Atomically changes the set of blocked signals and waits for a signal.

Format

#include <signal.h>

int sigsuspend (const sigset_t *signal_mask);


Argument

signal_mask

A pointer to a set of signals.

Description

The sigsuspend function replaces the signal mask of the process with the set of signals pointed to by the signal_mask argument. Then it suspends execution of the process until delivery of a signal whose action is either to execute a signal catching function or to terminate the process. You cannot block the SIGKILL or SIGSTOP signals with the sigsuspend function. If a program attempts to block either of these signals, sigsuspend gives no indication of the error.

If delivery of a signal causes the process to terminate, sigsuspend does not return. If delivery of a signal causes a signal catching function to execute, sigsuspend returns after the signal catching function returns, with the signal mask restored to the set that existed prior to the call to sigsuspend .

The sigsuspend function sets the signal mask and waits for an unblocked signal as one atomic operation. This means that signals cannot occur between the operations of setting the mask and waiting for a signal. If a program invokes sigprocmask SIG_SETMASK and sigsuspend separately, a signal that occurs between these functions is often not noticed by sigsuspend .

In normal usage, a signal is blocked by using the sigprocmask function at the beginning of a critical section. The process then determines whether there is work for it to do. If there is no work, the process waits for work by calling sigsuspend with the mask previously returned by sigprocmask .

If a signal is caught by the calling process and control is returned from the signal handler, the calling process resumes execution after sigsuspend , which always returns a value of - 1 and sets errno to EINTR.

See also sigpause and sigprocmask .


sigtimedwait (ALPHA, I64)

Suspends a calling thread and waits for queued signals to arrive.

Format

#include <signal.h>

int sigtimedwait (const sigset_t set, siginfo_t *info, const struct timespec *timeout);


Arguments

set

The set of signals to wait for.

info

Pointer to a siginfo structure that is receiving data describing the signal, including any application-defined data specified when the signal was posted.

timeout

A timeout for the wait. If timeout is NULL, the argument is ignored.

Description

The sigtimedwait function behaves the same as the sigwaitinfo function except that if none of the signals specified by set are pending, sigtimedwait waits for the time interval specified in the timespec structure referenced by timeout. If the timespec structure pointed to by timeout is zero-valued and if none of the signals specified by set are pending, then sigtimedwait returns immediately with an error.

See also sigwait and sigwaitinfo .

See Section 4.2 for more information on signal handling.


Return Values

x Upon successful completion, the signal number selected is returned.
- 1 Indicates that an error occurred; errno is set to one of the following values:
  • EINVAL -- The timeout argument specified a tv_nsec value less than 0 or greater than or equal to 1 billion.
  • EINTR -- The wait was interrupted by an unblocked, caught signal.
  • EAGAIN -- No signal specified by set was generated within the specified timeout period.

sigvec

Permanently assigns a handler for a specific signal.

Format

#include <signal.h>

int sigvec (int sigint, struct sigvec *sv, struct sigvec *osv);


Arguments

sigint

The signal identifier.

sv

Pointer to a sigvec structure (see the Description section).

osv

If osv is not NULL, the previous handling information for the signal is returned.

Description

If sv is not NULL, it specifies the address of a structure containing a pointer to a handler routine and mask to be used when delivering the specified signal, and a flag indicating whether the signal is to be processed on an alternative stack. If sv-->onstack has a value of 1, the system delivers the signal to the process on a signal stack specified with sigstack .

The sigvec function establishes a handler that remains established until explicitly removed or until the image terminates.

The sigvec structure is defined in the <signal.h> header file:


struct sigvec 
   { 
      int   (*handler)(); 
      int   mask; 
      int   onstack; 
   }; 
 

See Section 4.2 for more information on signal handling.


Return Values

0 Indicates that the call succeeded.
- 1 Indicates that an error occurred.

sigwait (ALPHA, I64)

Suspends a calling thread and waits for queued signals to arrive.

Format

#include <signal.h>

int sigwait (const sigset_t set, int *sig);


Arguments

set

The set of signals to wait for.

sig

Returns the signal number of the selected signal.

Description

The sigwait function suspends the calling thread until at least one of the signals in the set argument is in the caller's set of pending signals. When this happens, one of those signals is automatically selected and removed from the set of pending signals. The signal number identifying that signal is then returned in the location referenced by sig.

The effect is unspecified if any signals in the set argument are not blocked when the sigwait function is called.

The set argument is created using the set manipulation functions sigemptyset , sigfillset , sigaddset , and sigdelset .

If, while the sigwait function is waiting, a signal occurs that is eligible for delivery (that is, not blocked by the signal mask), that signal is handled asynchronously and the wait is interrupted.

See also sigtimedwait and sigwaitinfo .

See Section 4.2 for more information on signal handling.


Return Values

0 Upon successful completion, sigwait stores the signal number of the received signal at the location referenced by sig and returns 0.
nonzero Indicates that an error occurred; errno is set to the following value:
  • EINVAL -- The set argument contains an invalid or unsupported signal number.

sigwaitinfo (ALPHA, I64)

Suspends a calling thread and waits for queued signals to arrive.

Format

#include <signal.h>

int sigwaitinfo (const sigset_t set, siginfo_t *info);


Arguments

set

The set of signals to wait for.

info

Pointer to a siginfo structure that is receiving data describing the signal, including any application-defined data specified when the signal was posted.

Description

The sigwaitinfo function behaves the same as the sigwait function if the info argument is NULL.

If the info argument is non-NULL, the sigwaitinfo function behaves the same as sigwait , except that the selected signal number is stored in the si_signo member of the siginfo structure, and the cause of the signal is stored in the si_code member. If any value is queued to the selected signal, the first such queued value is dequeued and the value is stored in the si_value member of info. The system resource used to queue the signal is released and made available to queue other signals. If no value is queued, the content of the si_value member is undefined. If no further signals are queued for the selected signal, the pending indication for that signal is reset.

See also sigtimedwait and sigwait .

See Section 4.2 for more information on signal handling.


Return Values

x Upon successful completion, the signal number selected is returned.
- 1 Indicates that an error occurred; errno is set to one of the following values:
  • EINVAL -- The set argument contains an invalid or unsupported signal number.
  • EINTR -- The wait was interrupted by an unblocked, caught signal.

sin

Returns the sine of its radian argument.

Format

#include <math.h>

double sin (double x);

float sinf (float x); (ALPHA, I64)

long double sinl (long double x); (ALPHA, I64)

double sind (double x); (ALPHA, I64)

float sindf (float x); (ALPHA, I64)

long double sindl (long double x); (ALPHA, I64)


Argument

x

A radian expressed as a floating-point number.

Description

The sin functions compute the sine of x measured in radians.

The sind functions compute the sine of x measured in degrees.


Return Values

x The sine of the argument.
NaN x = ±Infinity or NaN; errno is set to EDOM.
0 Undeflow occurred; errno is set to ERANGE.

sinh

Returns the hyperbolic sine of its argument.

Format

#include <math.h>

double sinh (double x);

float sinhf (float x); (ALPHA, I64)

long double sinhl (long double x); (ALPHA, I64)


Argument

x

A real number.

Return Values

n The hyperbolic sine of the argument.
HUGE_VAL Overflow occurred; errno is set to ERANGE.
0 Underflow occurred; errno is set to ERANGE.
NaN x is NaN; errno is set to EDOM.

sleep

Suspends the execution of the current process (or thread in a threaded program) for at least the number of seconds indicated by its argument.

Format

#include <unistd.h>

unsigned int sleep (unsigned seconds); (_DECC_V4_SOURCE)

int sleep (unsigned seconds); (NOT _DECC_V4_SOURCE)


Argument

seconds

The number of seconds.

Description

The sleep function sleeps for the specified number of seconds, or until a signal is received, or until the process (or thread in a threaded program) executes a call to SYS$WAKE.

If a SIGALRM signal is generated, but blocked or ignored, the sleep function returns. For all other signals, a blocked or ignored signal does not cause sleep to return.


Return Values

x The number of seconds that the process awoke early.
0 If the process slept the full number of seconds specified by seconds.

snprintf

Performs formatted output to a string in memory.

Format

#include <stdio.h>

int snprintf (char *str, size_t n, const char *format_spec, ...);


Arguments

str

The address of the string that will receive the formatted output.

n

The size of the buffer referred to by str.

format_spec

A pointer to a character string that contains the format specification. For more information about format specifications and conversion characters, see Chapter 2.

...

Optional expressions whose resultant types correspond to conversion specifications given in the format specification.

If no conversion specifications are given, you may omit the output sources. Otherwise, the function calls must have at least as many output sources as there are conversion specifications, and the conversion specifications must match the types of the output sources.

Conversion specifications are matched to output sources in left-to-right order. Excess output pointers, if any, are ignored.


Description

The snprintf function is identical to the sprintf function with the addition of the n argument, which specifies the size of the buffer referred to by str.

On successful completion, snprintf returns the number of bytes (excluding the terminating null byte) that would be written to str if n is sufficiently large.

If n is 0, nothing is written, the number of bytes (excluding the terminating null) that would be written if n were sufficiently large are returned, and str might be a NULL pointer. Otherwise, output bytes beyond the n - 1st are discarded instead of being written to the array, and a null byte is written at the end of the bytes actually written into the array.

If an output error is encountered, a negative value is returned.

For a complete description of the format specification and the output source, see Chapter 2.


Return Values

x The number of bytes (excluding the terminating null byte) that would be written to str if n is sufficiently large.
Negative value Indicates an output error occurred. The function sets errno . For a list of errno values set by this function, see fprintf .

sprintf

Performs formatted output to a string in memory.

Format

#include <stdio.h>

int sprintf (char *str, const char *format_spec, ...);


Arguments

str

The address of the string that will receive the formatted output. It is assumed that this string is large enough to hold the output.

format_spec

A pointer to a character string that contains the format specification. For more information about format specifications and conversion characters, see Chapter 2.

...

Optional expressions whose resultant types correspond to conversion specifications given in the format specification.

If no conversion specifications are given, you may omit the output sources. Otherwise, the function calls must have at least as many output sources as there are conversion specifications, and the conversion specifications must match the types of the output sources.

Conversion specifications are matched to output sources in left-to-right order. Excess output pointers, if any, are ignored.


Description

The sprintf function places output followed by the null character (\0) in consecutive bytes starting at *str. The user must ensure that enough space is available.

Consider the following example of a conversion specification:


#include <stdio.h> 
 
main() 
{ 
   int  temp = 4, temp2 = 17; 
   char s[80]; 
 
   sprintf(s, "The answers are %d, and %d.", temp, temp2); 
} 

In this example, character string s has the following contents:


The answers are 4, and 17. 

For a complete description of the format specification and the output source, see Chapter 2.


Return Values

x The number of characters placed in the output string, not including the final null character.
Negative value Indicates an output error occurred. The function sets errno . For a list of errno values set by this function, see fprintf .

sqrt

Returns the square root of its argument.

Format

#include <math.h>

double sqrt (double x);

float sqrtf (float x); (ALPHA, I64)

long double sqrtl (long double x); (ALPHA, I64)


Argument

x

A real number.

Return Values

val The square root of x, if x is nonnegative.
0 x is negative; errno is set to EDOM.
NaN x is NaN; errno is set to EDOM.

srand

Initializes the pseudorandom-number generator rand .

Format

#include <math.h>

void srand (unsigned int seed);


Argument

seed

An unsigned integer.

Description

The srand function uses the argument as a seed for a new sequence of pseudorandom numbers to be returned by subsequent calls to rand .

If srand is then called with the same seed value, the sequence of pseudorandom numbers is repeated.

If rand is called before any calls to srand , the same sequence of pseudorandom numbers is generated as when srand is first called with a seed value of 1.


srand48

Initializes a 48-bit random-number generator.

Format

#include <stdlib.h>

void srand48 (long int seed_val);


Argument

seed_val

The initialization value to begin randomization. Changing this value changes the randomization pattern.

Description

The srand48 function initializes the random-number generator. You can use this function in your program before calling the drand48 , lrand48 , or mrand48 functions. (Although it is not recommended practice, constant default initializer values are automatically supplied if you call drand48 , lrand48 , or mrand48 without calling an initialization function).

The function works by generating a sequence of 48-bit integer values, Xi, according to the linear congruential formula:


       Xn+1 = (aXn+c)mod m        n >= 0 

The argument m equals 248 , so 48-bit integer arithmetic is performed. Unless you invoke the lcong48 function, the multiplier value a and the addend value c are:


      a = 5DEECE66D16 = 2736731631558
      c = B16 = 138

The initializer function srand48 sets the high-order 32 bits of Xi to the low-order 32 bits contained in its argument. The low-order 16 bits of Xi are set to the arbitrary value 330E _16 .

See also drand48 , lrand48 , and mrand48 .


Previous Next Contents Index