Thread: [R-gregmisc-users] SF.net SVN: r-gregmisc: [1067] trunk/fork/man
Brought to you by:
warnes
From: <wa...@us...> - 2007-03-06 23:15:33
|
Revision: 1067 http://svn.sourceforge.net/r-gregmisc/?rev=1067&view=rev Author: warnes Date: 2007-03-06 15:15:31 -0800 (Tue, 06 Mar 2007) Log Message: ----------- Create manual pages for handleSIGCLD() and restoreSIGCLD(), as well as appropriately modifying the pages for fork() and signal() Modified Paths: -------------- trunk/fork/man/fork.Rd trunk/fork/man/signal.Rd Added Paths: ----------- trunk/fork/man/handleSIGCLD.Rd Modified: trunk/fork/man/fork.Rd =================================================================== --- trunk/fork/man/fork.Rd 2007-03-06 22:47:29 UTC (rev 1066) +++ trunk/fork/man/fork.Rd 2007-03-06 23:15:31 UTC (rev 1067) @@ -162,12 +162,11 @@ close(con2) } -\dontrun{ -# Important: if we aren't going to explicitly wait() for the child -# process to exit, we need to tell the OS that we are ignoring child -# process signals so it will let us die cleanly. -signal("SIGCHLD","ignore") -} +## Important: if we aren't going to explicitly wait() for the child +## process to exit, we need to set up a dummy signal handler to collect +## (and then throw away) the exit status so that child processes will not +## become zombies when they exit +handleSIGCLD() # fork off the process pid <- fork(recieve) @@ -175,6 +174,9 @@ # start sending... send() } + +## restore SIGCLD signal handling to the previous state +restoreSIGCLD() } \keyword{programming} Added: trunk/fork/man/handleSIGCLD.Rd =================================================================== --- trunk/fork/man/handleSIGCLD.Rd (rev 0) +++ trunk/fork/man/handleSIGCLD.Rd 2007-03-06 23:15:31 UTC (rev 1067) @@ -0,0 +1,57 @@ +\name{handleSIGCLD} +\alias{handleSIGCLD} +\alias{restoreSIGCLD} +\title{Establish or remove a dummy handler for SIGCLD signals} +\description{ + Establish \code{handleSIGCLD} or remove \code{ignoreSIGCLD} a dummy + handler for SIGCLD signals +} +\usage{ +handleSIGCLD() +restoreSIGCLD() +} +\details{ + The \code{handleSIGCLD} function establishes a 'dummy' handler for + SIGCLD signals. It accepts signals from exiting child processes + created by \code{fork} and ignores them. This prevents child + processes from becoming 'zombies', which would occurs when the parent + process does not handle this signal. + + The \code{restoreSIGCLD} function restores the previous (lack of) + signal handler. +} +\value{ + No return value. +} +\note{ + The SIGCLD handling mechanism implemented by \code{handleSIGCLD} + should prevent zombie process creation on systems derived from both + SYSV and BSD UNIX, including Linux, Mac OSX, NetBSD, and Solaris. + } +\references{W.R. Stevens and S.A. Rago, Advanced Programming in the UNIX + environment, 2nd ed. (c) 2005, Pearson Education, pp 308-310.} +\author{Gregory R. Warnes \email{gre...@ro...} } +\seealso{ \code{\link{fork}}, \code{\link{wait}}, \code{\link{signal}} } +\examples{ + +## set up the dummy signal hander +handleSIGCLD() + +## Generate 100 child processes +for(i in 1:100) + { + pid = fork(slave=NULL) + if(pid==0) + { + ## don't do anything useful + exit() + } + else + pidList[i] <- pid + } + +## remove the dummy signal handler +restoreSIGCLD() +} +\keyword{programming} + Modified: trunk/fork/man/signal.Rd =================================================================== --- trunk/fork/man/signal.Rd 2007-03-06 22:47:29 UTC (rev 1066) +++ trunk/fork/man/signal.Rd 2007-03-06 23:15:31 UTC (rev 1067) @@ -26,11 +26,23 @@ \note{ Be very careful with this function. It can be used to totally confuse the R process. + + On sytems derived from BSD UNIX, setting the SIGCHLD signal to + 'ignore' will allow child processes to exit cleanly without becoming + zombies. This also prevents the parent process from checking the exit + status of children, since this information is no longer available once + child process disappears. On systems derived from SysV UNIX, setting + SIGCHLD to 'ignore' has no effect on the status of child processes + that exit, and they will still become zombies unless the exit status + is checked. See the \code{handleSIGCLD} function for a mechanism that + will prevent child processes from becoming zombies on both SYSV and + (hopefully) BSD-derived systems. } -\seealso{ \code{\link{sigval}}, \code{\link{fork}} } +\seealso{ \code{\link{sigval}}, \code{\link{fork}}, \code{\link{handleSIGCLD}} } \examples{ \dontrun{ -# Ignore child termination signals for forked processes +## Ignore child termination signals for forked processes NOTE: This +## mechanism only works on UNIX SYSV-derived systems. See Note above. signal("SIGCHLD","ignore") # Fork off a child process to say "Hi!". This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2007-03-24 21:28:24
|
Revision: 1084 http://svn.sourceforge.net/r-gregmisc/?rev=1084&view=rev Author: warnes Date: 2007-03-24 14:27:27 -0700 (Sat, 24 Mar 2007) Log Message: ----------- Add note of financial support from Metrum Modified Paths: -------------- trunk/fork/man/handleSIGCLD.Rd trunk/fork/man/signal.Rd Modified: trunk/fork/man/handleSIGCLD.Rd =================================================================== --- trunk/fork/man/handleSIGCLD.Rd 2007-03-23 22:53:00 UTC (rev 1083) +++ trunk/fork/man/handleSIGCLD.Rd 2007-03-24 21:27:27 UTC (rev 1084) @@ -30,7 +30,10 @@ } \references{W.R. Stevens and S.A. Rago, Advanced Programming in the UNIX environment, 2nd ed. (c) 2005, Pearson Education, pp 308-310.} -\author{Gregory R. Warnes \email{gre...@ro...} } +\author{Gregory R. Warnes \email{gr...@ra...}, + with financial support from Metrum Research Group, LLC + \url{http://www.metrumrg.com}. +} \seealso{ \code{\link{fork}}, \code{\link{wait}}, \code{\link{signal}} } \examples{ Modified: trunk/fork/man/signal.Rd =================================================================== --- trunk/fork/man/signal.Rd 2007-03-23 22:53:00 UTC (rev 1083) +++ trunk/fork/man/signal.Rd 2007-03-24 21:27:27 UTC (rev 1084) @@ -22,7 +22,10 @@ Nothing of interest. } \references{ See the unix man page for "signal" for more information} -\author{Gregory R. Warnes \email{gre...@ro...} } +\author{Gregory R. Warnes \email{gr...@ra...}, + with financial support from Metrum Research Group, LLC + \url{http://www.metrumrg.com}. +} \note{ Be very careful with this function. It can be used to totally confuse the R process. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |