Connecting Tech Pros Worldwide Help | Site Map

Create process problem

Member
 
Join Date: Jan 2008
Posts: 36
#1: Jan 23 '08
Hello my code is here.

here i am unable to execute my perl programs .
please help in this regards,
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use warnings;
  4. use strict;
  5.  
  6. use Carp;
  7. use Time::HiRes;
  8. use POSIX 'setsid';
  9.  
  10. my $child_pid;
  11. my $child_proc;
  12. my $cmd = "c:\\perl\\bin\\perl.exe";
  13.  
  14. my $debug = 1;
  15.  
  16. start_child();
  17.  
  18. sleep(5.0);
  19.  
  20. stop_child();
  21.  
  22. sub start_child
  23. {
  24.  
  25. #  die "cannot execute cmd: $cmd" unless -x $cmd;
  26.   if ($^O eq 'MSWin32') # Windows
  27.   {
  28.     require Win32::Process;
  29.     Win32::Process::Create($child_proc, $cmd, "e:\\automation\\sleep1.pl", 0, 0, ".") || confess "Could not spawn child: $!";
  30.     $child_pid=$child_proc->GetProcessID();
  31.     print $child_proc->GetProcessID();
  32.     start_child();
  33.     Win32::Process::Create($child_proc, $cmd, "e:\\automation\\sleep1.pl", 0, 0, ".") || confess "Could not spawn child: $!";
  34.     $child_pid=$child_proc->GetProcessID();
  35.     start_child();
  36.     Win32::Process::Create($child_proc, $cmd, "e:\\automation\\sleep1.pl", 0, 0, ".") || confess "Could not spawn child: $!";
  37.     $child_pid =$child_proc->GetProcessID();
  38.     start_child();
  39.     Win32::Process::Create($child_proc, $cmd, "e:\\automation\\sleep1.pl", 0, 0, ".") || confess "Could not spawn child: $!";
  40.     $child_pid=$child_proc->GetProcessID();
  41.     start_child();
  42.  
  43.   }
  44.   else # Unix
  45.   {
  46.     $SIG{CHLD} = 'IGNORE';
  47.     $child_pid = fork();
  48.     unless (defined $child_pid)
  49.     {
  50.       confess "Could not spawn child (Unix): $!";
  51.     }
  52.     if ($child_pid == 0 ) # child
  53.     {
  54.       unless ($debug)
  55.       {
  56.          open STDIN, "<", "/dev/null"   or die "Can't read /dev/null: $!";
  57.          open STDOUT, ">", "/dev/null"  or die "Can't write /dev/null: $!";
  58.       }
  59.       setsid or warn "setsid cannot start a new session: $!";
  60.       unless ($debug)
  61.       {
  62.          open STDERR, '>&STDOUT'  or die "Can't dup stdout: $!";
  63.       }
  64.       local $| = 1;
  65.       unless (exec($cmd))
  66.       {
  67.         confess "Could not start child: $cmd: $!";
  68.         CORE::exit(0);
  69.       }
  70.     }
  71.     # parent
  72.     $SIG{CHLD} = 'DEFAULT';
  73.   }
  74.   # catch early child exit, e.g. if program path is incorrect
  75.   sleep(1.0);
  76.   POSIX::waitpid(-1, POSIX::WNOHANG()); # clean up any defunct child process
  77.   if (kill(0,$child_pid))
  78.   {
  79.     print "Started child process id $child_pid\n";
  80.   }
  81.   else
  82.   {
  83.     warn "Child process exited quickly: $cmd: process $child_pid";
  84.   }
  85. }
  86.  
  87. sub stop_child
  88. {
  89.     if ($^O eq 'MSWin32') # Windows
  90.     {
  91.       Win32::Process::KillProcess($child_pid,0);
  92.     }
  93.     else # Unix
  94.     {
  95.       kill 9, $child_pid || warn "could not kill process $child_pid: $!";
  96.     }
  97.     print "Stopped child process id $child_pid\n";
  98. }
  99.  
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,567
#2: Jan 23 '08

re: Create process problem


Can you please supply us with any errors that you are getting from the execution of your code?

Regards,

Jeff
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#3: Jan 23 '08

re: Create process problem


mdshafi01,

this is not a code debugging service. Be as specific as possible and describe what happens when you run your program and any warnings or errors it generates.
Member
 
Join Date: Jan 2008
Posts: 36
#4: Jan 24 '08

re: Create process problem


Hello ,
Here i am not getting any error. But it is suppose to start sleep1.pl script. but it is not executing and also it is not throughing any error also.

shafi
Reply