| Skip Navigation Links | |
| Exit Print View | |
![]() | man pages section 3: Basic Library Functions Oracle Solaris 11 Information Library |
enable_extended_FILE_stdio(3C)
posix_spawnattr_getschedparam(3C)
posix_spawnattr_getschedpolicy(3C)
posix_spawnattr_getsigdefault(3C)
posix_spawnattr_getsigignore_np(3C)
posix_spawnattr_getsigmask(3C)
posix_spawnattr_setschedparam(3C)
posix_spawnattr_setschedpolicy(3C)
posix_spawnattr_setsigdefault(3C)
posix_spawnattr_setsigignore_np(3C)
posix_spawnattr_setsigmask(3C)
posix_spawn_file_actions_addclose(3C)
posix_spawn_file_actions_addclosefrom_np(3C)
posix_spawn_file_actions_adddup2(3C)
posix_spawn_file_actions_addopen(3C)
posix_spawn_file_actions_destroy(3C)
posix_spawn_file_actions_init(3C)
pthread_attr_getdetachstate(3C)
pthread_attr_getinheritsched(3C)
pthread_attr_getschedparam(3C)
pthread_attr_getschedpolicy(3C)
pthread_attr_setdetachstate(3C)
pthread_attr_setinheritsched(3C)
pthread_attr_setschedparam(3C)
pthread_attr_setschedpolicy(3C)
pthread_barrierattr_destroy(3C)
pthread_barrierattr_getpshared(3C)
pthread_barrierattr_setpshared(3C)
pthread_condattr_getpshared(3C)
pthread_condattr_setpshared(3C)
pthread_cond_reltimedwait_np(3C)
pthread_key_create_once_np(3C)
pthread_mutexattr_getprioceiling(3C)
pthread_mutexattr_getprotocol(3C)
pthread_mutexattr_getpshared(3C)
pthread_mutexattr_getrobust(3C)
pthread_mutexattr_setprioceiling(3C)
pthread_mutexattr_setprotocol(3C)
pthread_mutexattr_setpshared(3C)
pthread_mutexattr_setrobust(3C)
pthread_mutex_getprioceiling(3C)
pthread_mutex_reltimedlock_np(3C)
pthread_mutex_setprioceiling(3C)
pthread_rwlockattr_destroy(3C)
pthread_rwlockattr_getpshared(3C)
pthread_rwlockattr_setpshared(3C)
pthread_rwlock_reltimedrdlock_np(3C)
pthread_rwlock_reltimedwrlock_np(3C)
pthread_rwlock_timedrdlock(3C)
pthread_rwlock_timedwrlock(3C)
rctlblk_get_enforced_value(3C)
- non-local goto
#include <setjmp.h>intsetjmp(jmp_bufenv);
intsigsetjmp(sigjmp_bufenv,intsavemask);
voidlongjmp(jmp_bufenv,intval);
voidsiglongjmp(sigjmp_bufenv,intval);
These functions are useful for dealing with errors and interrupts encounteredin a low-level subroutine of a program.
Thesetjmp() function saves its stack environment inenv for later usebylongjmp().
Thesigsetjmp() function saves the calling process's registers and stack environment (seesigaltstack(2)) inenv for later use bysiglongjmp(). Ifsavemask isnon-zero, the calling process's signal mask (seesigprocmask(2)) and scheduling parameters (seepriocntl(2))are also saved.
Thelongjmp() function restores the environment saved by the last call ofsetjmp() with the correspondingenv argument. Afterlongjmp() completes, program execution continuesas if the corresponding call tosetjmp() had just returned thevalueval. The caller ofsetjmp() must not have returned inthe interim. Thelongjmp() function cannot causesetjmp() to return thevalue 0. Iflongjmp() is invoked with a second argument of 0,setjmp() will return 1. At the time of the second return fromsetjmp(), all external and static variables have values as of the timelongjmp() is called (seeEXAMPLES).
Thesiglongjmp() function restores the environment saved by the last call ofsigsetjmp() with the correspondingenv argument. Aftersiglongjmp() completes, program execution continuesas if the corresponding call tosigsetjmp() had just returned the valueval. Thesiglongjmp() function cannot causesigsetjmp() to return the value 0. Ifsiglongjmp() is invoked with a second argument of 0,sigsetjmp()will return 1. At the time of the second return fromsigsetjmp(), allexternal and static variables have values as of the timesiglongjmp() wascalled.
If a signal-catching function interruptssleep(3C) and callssiglongjmp() to restore anenvironment saved prior to thesleep() call, the action associated withSIGALRM andtime it is scheduled to be generated are unspecified. It is alsounspecified whether theSIGALRM signal is blocked, unless the process's signal maskis restored as part of the environment.
Thesiglongjmp() function restores the saved signal mask if and onlyif theenv argument was initialized by a call to thesigsetjmp() function with a non-zerosavemask argument.
The values of register and automatic variables are undefined. Register or automaticvariables whose value must be relied upon must be declared as volatile.
If the return is from a direct invocation,setjmp() andsigsetjmp() return0. If the return is from a call tolongjmp(),setjmp() returnsa non-zero value. If the return is from a call tosiglongjmp(),sigsetjmp() returns a non-zero value.
Afterlongjmp() is completed, program execution continues as if the corresponding invocationofsetjmp() had just returned the value specified byval. Thelongjmp()function cannot causesetjmp() to return 0; ifval is 0,setjmp() returns1.
Aftersiglongjmp() is completed, program execution continues as if the corresponding invocationofsigsetjmp() had just returned the value specified byval. Thesiglongjmp()function cannot causesigsetjmp() to return 0; ifval is 0,sigsetjmp()returns 1.
Example 1 Example ofsetjmp() andlongjmp() functions.
The following example uses bothsetjmp() andlongjmp() to return the flowof control to the appropriate instruction block:
#include <stdio.h>#include <setjmp.h>#include <signal.h>#include <unistd.h>jmp_buf env; static void signal_handler();main( ) { int returned_from_longjump, processing = 1; unsigned int time_interval = 4; if ((returned_from_longjump = setjmp(env)) != 0) switch (returned_from_longjump) { case SIGINT: printf("longjumped from interrupt %d\n",SIGINT); break; case SIGALRM: printf("longjumped from alarm %d\n",SIGALRM); break; } (void) signal(SIGINT, signal_handler); (void) signal(SIGALRM, signal_handler); alarm(time_interval); while (processing) { printf(" waiting for you to INTERRUPT (cntrl-C) ...\n"); sleep(1); } /* end while forever loop */}static void signal_handler(sig)int sig; { switch (sig) { case SIGINT: ... /* process for interrupt */ longjmp(env,sig); /* break never reached */ case SIGALRM: ... /* process for alarm */ longjmp(env,sig); /* break never reached */ default: exit(sig); }}When this example is compiled and executed, and the user sends aninterrupt signal, the output will be:
longjumped from interrupt
Additionally, every 4 seconds the alarm will expire, signalling this process, andthe output will be:
longjumped from alarm
Seeattributes(5) for descriptions of the following attributes:
|
getcontext(2),priocntl(2),sigaction(2),sigaltstack(2),sigprocmask(2),signal(3C),attributes(5),standards(5)
Iflongjmp() orsiglongjmp() are called even thoughenv was never primedby a call tosetjmp() orsigsetjmp(), or when the last suchcall was in a function that has since returned, the results are undefined.
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.Legal Notices | ![]() ![]() |