[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. |