| 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)
- close or iterate over open file descriptors
#include <stdlib.h>voidclosefrom(intlowfd);
intfdwalk(int (*func)(void *,int),void *cd);
Theclosefrom() function callsclose(2) on all open file descriptors greater thanor equal tolowfd.
The effect ofclosefrom(lowfd) is the same as the code
#include <sys/resource.h>struct rlimit rl;int i;getrlimit(RLIMIT_NOFILE, &rl);for (i = lowfd; i < rl.rlim_max; i++) (void) close(i);
except thatclose() is called only on file descriptors that are actuallyopen, not on every possible file descriptor greater than or equal tolowfd, andclose() is also called on any open file descriptors greaterthan or equal torl.rlim_max (andlowfd), should any exist.
Thefdwalk() function first makes a list of all currently open filedescriptors. Then for each file descriptor in the list, it calls theuser-defined function,func(cd,fd), passing it the pointer to the callback data,cd,and the value of the file descriptor from the list,fd. The list is processed in file descriptor value order, lowest numeric valuefirst.
Iffunc() returns a non-zero value, the iteration over the list isterminated andfdwalk() returns the non-zero value returned byfunc(). Otherwise,fdwalk() returns 0 after having calledfunc() for every file descriptor in thelist.
Thefdwalk() function can be used for fine-grained control over the closingof file descriptors. For example, theclosefrom() function can be implementedas:
static intclose_func(void *lowfdp, int fd){ if (fd >= *(int *)lowfdp) (void) close(fd); return (0);}voidclosefrom(int lowfd){ (void) fdwalk(close_func, &lowfd);}Thefdwalk() function can then be used to count the number ofopen files in the process.
No return value is defined forclosefrom(). Ifclose() fails for anyof the open file descriptors, the error is ignored and the filedescriptors whoseclose() operation failed might remain open on return fromclosefrom().
Thefdwalk() function returns the return value of the last call tothe callback functionfunc(), or 0 iffunc() is never called (noopen files).
No errors are defined. Theclosefrom() andfdwalk() functions do not seterrno buterrno can be set byclose() or by another functioncalled by the callback function,func().
directory (list of open files)
The act of closing all open file descriptors should be performed onlyas the first action of a daemon process. Closing file descriptorsthat are in use elsewhere in the current process normally leads todisastrous results.
Seeattributes(5) for descriptions of the following attributes:
|
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.Legal Notices | ![]() ![]() |