[R-gregmisc-users] SF.net SVN: r-gregmisc: [1043] trunk/fork
Brought to you by:
warnes
From: <wa...@us...> - 2007-02-05 23:10:39
|
Revision: 1043 http://svn.sourceforge.net/r-gregmisc/?rev=1043&view=rev Author: warnes Date: 2007-02-05 15:08:43 -0800 (Mon, 05 Feb 2007) Log Message: ----------- Add signal() command to allow ignoring signals Modified Paths: -------------- trunk/fork/DESCRIPTION trunk/fork/R/signame.R trunk/fork/man/fork.Rd trunk/fork/man/signame.Rd trunk/fork/src/fork.c Added Paths: ----------- trunk/fork/R/signal.R trunk/fork/man/signal.Rd Modified: trunk/fork/DESCRIPTION =================================================================== --- trunk/fork/DESCRIPTION 2007-01-28 10:42:24 UTC (rev 1042) +++ trunk/fork/DESCRIPTION 2007-02-05 23:08:43 UTC (rev 1043) @@ -1,6 +1,6 @@ Package: fork Title: R functions for handling multiple processes. -Version: 1.0.2 +Version: 1.0.3 Author: Gregory R. Warnes <wa...@bs...> Description: These functions provides simple wrappers around the Unix process management API calls: fork, wait, waitpid, kill, and _exit. This Added: trunk/fork/R/signal.R =================================================================== --- trunk/fork/R/signal.R (rev 0) +++ trunk/fork/R/signal.R 2007-02-05 23:08:43 UTC (rev 1043) @@ -0,0 +1,30 @@ +# $Id: kill.R 340 2004-05-25 19:12:32Z warnes $ + +signal <- function(signal, action=c("ignore","restore") ) + { + action=match.args(action) + + if(is.character(signal)) + sig=sigval(signal)$val + else (is.numeric(signal) && !is.na(signal)) + sig=signal + else + stop("Illegal value for signal") + + act <- switch( + action, + "ignore"=0, + "restore"=1 + ) + + msg1 = + + .C( + "Rfork_signal", + as.integer(signal), + as.integer(act), + PACKAGE="fork" + ) + invisible() + } + Modified: trunk/fork/R/signame.R =================================================================== --- trunk/fork/R/signame.R 2007-01-28 10:42:24 UTC (rev 1042) +++ trunk/fork/R/signame.R 2007-02-05 23:08:43 UTC (rev 1043) @@ -20,7 +20,8 @@ val=integer(1), desc=character(1), PACKAGE="fork") - unlist(retval) + #retval <- unlist(retval) + retval } siglist <- function() Modified: trunk/fork/man/fork.Rd =================================================================== --- trunk/fork/man/fork.Rd 2007-01-28 10:42:24 UTC (rev 1042) +++ trunk/fork/man/fork.Rd 2007-02-05 23:08:43 UTC (rev 1043) @@ -162,8 +162,15 @@ close(con2) } +# 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") +# fork off the process pid <- fork(recieve) + +# start sending... send() } } Added: trunk/fork/man/signal.Rd =================================================================== --- trunk/fork/man/signal.Rd (rev 0) +++ trunk/fork/man/signal.Rd 2007-02-05 23:08:43 UTC (rev 1043) @@ -0,0 +1,49 @@ +\name{signal} +\alias{signal} +\title{Enable or disable handling of signals} +\description{ + This function allows enabling or disabling handling of the specified signal. +} +\usage{ +signal(signal, action = c("ignore", "default")) +} +\arguments{ + \item{signal}{Signal handler to manipulate, either as a numeric id or + character mnemonic} + \item{action}{Either "ignore" or "default"} +} +\details{ + It is occasionally necessary to instruct the R process to ignore + certain signals. This function allows changing the status of a signal + to either igore the signal (SIG_IGN="ignore") or to the OS's default + handler (SIG_DFL="default") +} +\value{ + Nothing of interest. +} +\references{ See the unix man page for "signal" for more information} +\author{Gregory R. Warnes \email{gre...@ro...} } +\note{ + Be very careful with this function. It can be used to totally + confuse the R process. +} +\seealso{ \code{\link{sigval}}, \code{\link{fork}} } +\examples{ + +# Ignore child termination signals for forked processes +signal("SIGCHLD","ignore") + +# Fork off a child process to say "Hi!". + { + pid = fork(slave=NULL) + if(pid==0) { + # only runs in the child process + cat("Hi from the child process!\n"); + exit() # force process to die + } + } + +} +% Add one or more standard keywords, see file 'KEYWORDS' in the +% R documentation directory. +\keyword{programming} Modified: trunk/fork/man/signame.Rd =================================================================== --- trunk/fork/man/signame.Rd 2007-01-28 10:42:24 UTC (rev 1042) +++ trunk/fork/man/signame.Rd 2007-02-05 23:08:43 UTC (rev 1043) @@ -22,7 +22,7 @@ compile time. } \value{ - A vector (\code{signame}, \code{sigval}) or data frame + A list (\code{signame}, \code{sigval}) or data frame (\code{siglist}) containing the components: \item{name}{Symbolic name} \item{val}{Integer value} Modified: trunk/fork/src/fork.c =================================================================== --- trunk/fork/src/fork.c 2007-01-28 10:42:24 UTC (rev 1042) +++ trunk/fork/src/fork.c 2007-02-05 23:08:43 UTC (rev 1043) @@ -266,3 +266,15 @@ return list; } +void Rfork_signal(int *sig, int *action) +{ + sig_t func; + + if(*action==0) + func = SIG_IGN; + else + func = SIG_DFL; + + signal( *sig, func ); +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |