|
Functions having to do with multithreading. More...
Files | |
file | daemon.h |
Create background or daemon processes. | |
file | threads.h |
Architecture-specific thread function calls. | |
Functions | |
ARCH_API int | ArchCloseAllFiles (int nExcept, const int *exceptFds) |
Close all file descriptors (with possible exceptions) | |
ARCH_API bool | ArchIsMainThread () |
Return true if the calling thread is the main thread, false otherwise. | |
Functions having to do with multithreading.
ARCH_API int ArchCloseAllFiles | ( | int | nExcept, |
const int * | exceptFds | ||
) |
Close all file descriptors (with possible exceptions)
ArchCloseAllFiles
will close all file descriptors open in the current process. Occasionally you'd like to close all files except for some small subset (like 0, 1, and 2). The nExcept
and exceptFds
arguments can be used to provide the list of exceptions. ArchDaemonizeProcess
uses this method to close all unwanted file descriptors in the daemon process.
nExcept
should be the number of elements in the exceptFds
array. Invalid file descriptors in exceptFds are ignored.
fork(2)
call to close all unwanted file descriptors. However, it does not flush stdio buffers, wait for processes opened with popen, shut down the X11 display connection, or anything. It just slams closed all the file descriptors. This is appropriate following a fork(2)
call as all these file descriptors are duplicates of the ones in the parent process and shutting down the X11 display connection would mess up the parent's X11 display. But you shouldn't use ArchCloseAllFiles
unless you know what you are doing.errno
will be set to an appropriate value. Returns 0 on success. ARCH_API bool ArchIsMainThread | ( | ) |
Return true if the calling thread is the main thread, false otherwise.