Thread: [R-gregmisc-users] SF.net SVN: r-gregmisc: [1065] trunk/fork/tests
Brought to you by:
warnes
From: <wa...@us...> - 2007-03-06 22:48:36
|
Revision: 1065 http://svn.sourceforge.net/r-gregmisc/?rev=1065&view=rev Author: warnes Date: 2007-03-06 14:47:07 -0800 (Tue, 06 Mar 2007) Log Message: ----------- Create SysV and BSD tests for code to prevent zombie process creation, update code that intentionally creates zombies. Move sub-process creation and zombie test code to a function for use by all three test files Modified Paths: -------------- trunk/fork/tests/test_many_fork_broken.R Added Paths: ----------- trunk/fork/tests/checkZombies.R trunk/fork/tests/test_many_fork_SysV.R Removed Paths: ------------- trunk/fork/tests/test_many_fork.R Added: trunk/fork/tests/checkZombies.R =================================================================== --- trunk/fork/tests/checkZombies.R (rev 0) +++ trunk/fork/tests/checkZombies.R 2007-03-06 22:47:07 UTC (rev 1065) @@ -0,0 +1,48 @@ +checkZombies <- function() + { + cat("Generating 100 child processes (to become zombies)...\n") + pidList <- integer(100) + for(i in 1:100) + { + pid = fork(slave=NULL) + if(pid==0) + { + ##cat("Hi from child process",getpid(),".\n"); + ##Sys.sleep(10); + ##cat("Bye from child process",getpid(),".\n"); + exit() + } + else + pidList[i] <- pid + } + + cat("Give them 10 seconds to die and exit..\n") + Sys.sleep(10) + + cat("Check the process table to see if there are any zombies...\n") + if(TRUE) # BSD-style 'ps' command (Linux, Mac OSX, NetBSD) + { + statusList = system("ps -o stat", intern=TRUE)[-1] + } else # SysV-style 'ps' command (Solaris) + { + statusList = system("ps -o s", intern=TRUE)[-1] + } + + zombies = grep("[Zz]", statusList, value=TRUE) + if(length(zombies)>50) + { + retval = TRUE + cat(length(zombies), " Zombie Processes Present!\n") + } + else + { + retval = FALSE + cat("Done. No Zombies present.\n") + } + + + for(i in 1:100) + wait(pidList[i], nohang=FALSE) + + return(retval) +} Deleted: trunk/fork/tests/test_many_fork.R =================================================================== --- trunk/fork/tests/test_many_fork.R 2007-03-06 22:44:25 UTC (rev 1064) +++ trunk/fork/tests/test_many_fork.R 2007-03-06 22:47:07 UTC (rev 1065) @@ -1,27 +0,0 @@ -library(fork) - -# ignore sigchld signals so child processes will die cleanly -#signal("SIGCHLD","ignore") - -# start signal handler -.C("R_install_sigcld_handler") - -cat("Hi from the parent process\n"); - -for(i in 1:100) - { - pid = fork(slave=NULL) - if(pid==0) - { - cat("Hi from child process",getpid(),".\n"); - Sys.sleep(10); - cat("Bye from child process",getpid(),".\n"); - exit() - } - } - -Sys.sleep(300) -cat("Bye from the parent process",pid,".\n"); - -# remove signal handler -.C("R_restore_sigcld_handler") Added: trunk/fork/tests/test_many_fork_SysV.R =================================================================== --- trunk/fork/tests/test_many_fork_SysV.R (rev 0) +++ trunk/fork/tests/test_many_fork_SysV.R 2007-03-06 22:47:07 UTC (rev 1065) @@ -0,0 +1,19 @@ +## This script starts child processes, and sets the SIGCHLD hander to +## "ignore". On Sys5 derived systems, this should cause child +## processes to exit and die cleanly without the parent process +## querying the exit state. IE, no zombie processes will be created. + +library(fork) + +## ignore sigchld signals so child processes will die cleanly +signal("SIGCHLD","ignore") + +source("checkZombies.R") + +nZombies <- checkZombies() + +if(nZombies) + stop("Zombie processes created") +else + cat("Success!\n") + Modified: trunk/fork/tests/test_many_fork_broken.R =================================================================== --- trunk/fork/tests/test_many_fork_broken.R 2007-03-06 22:44:25 UTC (rev 1064) +++ trunk/fork/tests/test_many_fork_broken.R 2007-03-06 22:47:07 UTC (rev 1065) @@ -4,33 +4,11 @@ library(fork) -cat("Generating 100 child processes (to become zombies)...\n") -for(i in 1:100) - { - pid = fork(slave=NULL) - if(pid==0) - { - #cat("Hi from child process",getpid(),".\n"); - #Sys.sleep(10); - #cat("Bye from child process",getpid(),".\n"); - exit() - } - } +source("checkZombies.R") -cat("Give them 10 seconds to die and exit..\n") -Sys.sleep(10) +nZombies <- checkZombies() -cat("Check the process table to see if there are any zombies...\n") -if(TRUE) # BSD-style PS command (Linux, Mac OSX, NetBSD) -{ - statusList = system("ps -o stat", intern=TRUE)[-1] -} else -{ - statusList = system("ps -o s", intern=TRUE)[-1] -} - -zombies = grep("[Zz]", statusList, value=TRUE) -if(length(zombies)>50) - stop(length(zombies), " Zombie Processes Present!") +if(nZombies) + stop("Zombie processes created") else - cat("Done. No Zombies present.\n") + cat("Success!\n") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2007-03-06 23:28:29
|
Revision: 1069 http://svn.sourceforge.net/r-gregmisc/?rev=1069&view=rev Author: warnes Date: 2007-03-06 15:28:27 -0800 (Tue, 06 Mar 2007) Log Message: ----------- Improve regression tests, add saved .Rout files for doing regression testing. Modified Paths: -------------- trunk/fork/tests/checkZombies.R trunk/fork/tests/test_many_fork_BSD.R trunk/fork/tests/test_many_fork_SysV.R trunk/fork/tests/test_many_fork_broken.R Added Paths: ----------- trunk/fork/tests/test_many_fork_BSD.Rout.save trunk/fork/tests/test_many_fork_SysV.Rout.save trunk/fork/tests/test_many_fork_broken.Rout.save Modified: trunk/fork/tests/checkZombies.R =================================================================== --- trunk/fork/tests/checkZombies.R 2007-03-06 23:17:34 UTC (rev 1068) +++ trunk/fork/tests/checkZombies.R 2007-03-06 23:28:27 UTC (rev 1069) @@ -32,6 +32,7 @@ if(length(zombies)>50) { retval = TRUE + warning(length(zombies), " Zombie Processes Present!\n") cat(length(zombies), " Zombie Processes Present!\n") } else Modified: trunk/fork/tests/test_many_fork_BSD.R =================================================================== --- trunk/fork/tests/test_many_fork_BSD.R 2007-03-06 23:17:34 UTC (rev 1068) +++ trunk/fork/tests/test_many_fork_BSD.R 2007-03-06 23:28:27 UTC (rev 1069) @@ -12,11 +12,5 @@ nZombies <- checkZombies() -if(nZombies) { - stop("Zombie processes created") -} else { - cat("Success!\n") -} - # remove signal handler restoreSIGCLD() Added: trunk/fork/tests/test_many_fork_BSD.Rout.save =================================================================== --- trunk/fork/tests/test_many_fork_BSD.Rout.save (rev 0) +++ trunk/fork/tests/test_many_fork_BSD.Rout.save 2007-03-06 23:28:27 UTC (rev 1069) @@ -0,0 +1,40 @@ + +R version 2.4.1 (2006-12-18) +Copyright (C) 2006 The R Foundation for Statistical Computing +ISBN 3-900051-07-0 + +R is free software and comes with ABSOLUTELY NO WARRANTY. +You are welcome to redistribute it under certain conditions. +Type 'license()' or 'licence()' for distribution details. + +R is a collaborative project with many contributors. +Type 'contributors()' for more information and +'citation()' on how to cite R or R packages in publications. + +Type 'demo()' for some demos, 'help()' for on-line help, or +'help.start()' for an HTML browser interface to help. +Type 'q()' to quit R. + +> ## This script starts child processes, and sets up a 'dummy' SIGCLD +> ## hander to handle child process notifications. Hopefully on both BSD +> ## and Sys5 derived systems, this should cause child processes to exit +> ## and die cleanly, IE without becoming zombies. +> +> library(fork) +> +> ## start signal handler +> handleSIGCLD() +Installing SIGCHLD signal handler...Done. +> +> source("checkZombies.R") +> +> nZombies <- checkZombies() +Generating 100 child processes (to become zombies)... +Give them 10 seconds to die and exit.. +Check the process table to see if there are any zombies... +Done. No Zombies present. +> +> # remove signal handler +> restoreSIGCLD() +Restoring original SIGCHLD signal handler...Done. +> Modified: trunk/fork/tests/test_many_fork_SysV.R =================================================================== --- trunk/fork/tests/test_many_fork_SysV.R 2007-03-06 23:17:34 UTC (rev 1068) +++ trunk/fork/tests/test_many_fork_SysV.R 2007-03-06 23:28:27 UTC (rev 1069) @@ -12,8 +12,3 @@ nZombies <- checkZombies() -if(nZombies) - stop("Zombie processes created") -else - cat("Success!\n") - Added: trunk/fork/tests/test_many_fork_SysV.Rout.save =================================================================== --- trunk/fork/tests/test_many_fork_SysV.Rout.save (rev 0) +++ trunk/fork/tests/test_many_fork_SysV.Rout.save 2007-03-06 23:28:27 UTC (rev 1069) @@ -0,0 +1,36 @@ + +R version 2.4.1 (2006-12-18) +Copyright (C) 2006 The R Foundation for Statistical Computing +ISBN 3-900051-07-0 + +R is free software and comes with ABSOLUTELY NO WARRANTY. +You are welcome to redistribute it under certain conditions. +Type 'license()' or 'licence()' for distribution details. + +R is a collaborative project with many contributors. +Type 'contributors()' for more information and +'citation()' on how to cite R or R packages in publications. + +Type 'demo()' for some demos, 'help()' for on-line help, or +'help.start()' for an HTML browser interface to help. +Type 'q()' to quit R. + +> ## This script starts child processes, and sets the SIGCHLD hander to +> ## "ignore". On Sys5 derived systems, this should cause child +> ## processes to exit and die cleanly without the parent process +> ## querying the exit state. IE, no zombie processes will be created. +> +> library(fork) +> +> ## ignore sigchld signals so child processes will die cleanly +> signal("SIGCHLD","ignore") +> +> source("checkZombies.R") +> +> nZombies <- checkZombies() +Generating 100 child processes (to become zombies)... +Give them 10 seconds to die and exit.. +Check the process table to see if there are any zombies... +Done. No Zombies present. +> +> Modified: trunk/fork/tests/test_many_fork_broken.R =================================================================== --- trunk/fork/tests/test_many_fork_broken.R 2007-03-06 23:17:34 UTC (rev 1068) +++ trunk/fork/tests/test_many_fork_broken.R 2007-03-06 23:28:27 UTC (rev 1069) @@ -8,7 +8,3 @@ nZombies <- checkZombies() -if(nZombies) - stop("Zombie processes created") -else - cat("Success!\n") Added: trunk/fork/tests/test_many_fork_broken.Rout.save =================================================================== --- trunk/fork/tests/test_many_fork_broken.Rout.save (rev 0) +++ trunk/fork/tests/test_many_fork_broken.Rout.save 2007-03-06 23:28:27 UTC (rev 1069) @@ -0,0 +1,35 @@ + +R version 2.4.1 (2006-12-18) +Copyright (C) 2006 The R Foundation for Statistical Computing +ISBN 3-900051-07-0 + +R is free software and comes with ABSOLUTELY NO WARRANTY. +You are welcome to redistribute it under certain conditions. +Type 'license()' or 'licence()' for distribution details. + +R is a collaborative project with many contributors. +Type 'contributors()' for more information and +'citation()' on how to cite R or R packages in publications. + +Type 'demo()' for some demos, 'help()' for on-line help, or +'help.start()' for an HTML browser interface to help. +Type 'q()' to quit R. + +> ## This script starts child processes, but doesn't do anything about +> ## collecting or ignoring child process return status. Consequently, it should +> ## generate zombie child processes. +> +> library(fork) +> +> source("checkZombies.R") +> +> nZombies <- checkZombies() +Generating 100 child processes (to become zombies)... +Give them 10 seconds to die and exit.. +Check the process table to see if there are any zombies... +100 Zombie Processes Present! +Warning message: +100 Zombie Processes Present! + in: checkZombies() +> +> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |