1*53bd3188Sjmc.\" $OpenBSD: pthread_atfork.3,v 1.12 2015/05/15 18:47:53 jmc Exp $ 248c333a3Sbrad.\" 3829d3fd5Sjmc.\" David Leonard <d@openbsd.org>, 1999. Public domain. 49a3bbfb7Sbrad.\" 5*53bd3188Sjmc.Dd $Mdocdate: May 15 2015 $ 648c333a3Sbrad.Dt PTHREAD_ATFORK 3 748c333a3Sbrad.Os 848c333a3Sbrad.Sh NAME 948c333a3Sbrad.Nm pthread_atfork 10829d3fd5Sjmc.Nd specify handler functions to call when the process forks 1148c333a3Sbrad.Sh SYNOPSIS 1286f9d4cdStedu.In pthread.h 1348c333a3Sbrad.Ft int 1448c333a3Sbrad.Fn pthread_atfork "void (*prepare)(void)" "void (*parent)(void)" "void (*child)(void)" 1548c333a3Sbrad.Sh DESCRIPTION 1648c333a3SbradThe 1748c333a3Sbrad.Fn pthread_atfork 1848c333a3Sbradfunction declares fork handlers to be called before and after 199fc11cfaSguenther.Xr fork 2 , 2048c333a3Sbradin the context of the thread that called 219fc11cfaSguenther.Xr fork 2 . 2248c333a3SbradThe 2348c333a3Sbrad.Fa prepare 2448c333a3Sbradfork handler will be called before 259fc11cfaSguenther.Xr fork 2 2648c333a3Sbradprocessing commences. 2748c333a3SbradThe 2848c333a3Sbrad.Fa parent 29829d3fd5Sjmcfork handler will be called after 309fc11cfaSguenther.Xr fork 2 3148c333a3Sbradprocessing completes in the parent process. 3248c333a3SbradThe 3348c333a3Sbrad.Fa child 3448c333a3Sbradfork handler will be called after 359fc11cfaSguenther.Xr fork 2 3648c333a3Sbradprocessing completes in the child process. 37829d3fd5SjmcIf no handling is desired at 38829d3fd5Sjmcone or more of these three points, 39829d3fd5Sjmcthe corresponding fork handler 40829d3fd5Sjmcaddress(es) may be set to 41829d3fd5Sjmc.Dv NULL . 429a546be6Sfgsch.Pp 43829d3fd5SjmcThe order of calls to 4448c333a3Sbrad.Fn pthread_atfork 45829d3fd5Sjmcis significant. 4648c333a3SbradThe 4748c333a3Sbrad.Fa parent 4848c333a3Sbradand 4948c333a3Sbrad.Fa child 50829d3fd5Sjmcfork handlers will be called in the order in which they were established 51829d3fd5Sjmcby calls to 52829d3fd5Sjmc.Fn pthread_atfork . 53829d3fd5SjmcThe 5448c333a3Sbrad.Fa prepare 5548c333a3Sbradfork handlers will be called in the opposite order. 569fc11cfaSguenther.Pp 579fc11cfaSguentherIf a shared object is unloaded from process memory using 589fc11cfaSguenther.Xr dlclose 3 , 599fc11cfaSguentherthen any functions registered by calling 609fc11cfaSguenther.Fn pthread_atfork 619fc11cfaSguentherfrom that shared object will be unregistered without being invoked. 629fc11cfaSguentherNote that it is the source of the call to 639fc11cfaSguenther.Fn pthread_atfork 649fc11cfaSguentherthat matters, not the source of the functions that were registered. 6548c333a3Sbrad.Sh RETURN VALUES 6648c333a3SbradUpon successful completion, 6748c333a3Sbrad.Fn pthread_atfork 68829d3fd5Sjmcwill return a value of zero. 69829d3fd5SjmcOtherwise, an error number will be 70829d3fd5Sjmcreturned to indicate the error. 7148c333a3Sbrad.Sh ERRORS 7248c333a3Sbrad.Fn pthread_atfork 73829d3fd5Sjmcwill fail if: 7448c333a3Sbrad.Bl -tag -width Er 7548c333a3Sbrad.It Bq Er ENOMEM 7648c333a3SbradInsufficient table space exists to record the fork handler addresses. 77829d3fd5SjmcNone of the handler lists are modified. 7848c333a3Sbrad.El 7948c333a3Sbrad.Sh SEE ALSO 80829d3fd5Sjmc.Xr fork 2 , 819fc11cfaSguenther.Xr atexit 3 , 829fc11cfaSguenther.Xr dlclose 3 8348c333a3Sbrad.Sh STANDARDS 8448c333a3Sbrad.Fn pthread_atfork 85829d3fd5Sjmcconforms to 86829d3fd5Sjmc.St -p1003.1-2004 . 879fc11cfaSguenther.Pp 889fc11cfaSguentherThe behavior when a shared object is unloaded is an extension to 899fc11cfaSguentherthat standard. 90