CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
I need some help.


New User

Nov 25, 2011, 8:17 AM

Post #1 of 1 (332 views)
I need some help. Can't Post

hey all, I hope your all well. I need some help implementing a command input using the <STDIN> and chomp function into a forked program.

here is the code so far..



#start main method
#variables list
my( $i, $rc, $pid);
for ($i=0; $i<0; $i++)#start for loop

if (($i % 2) == 0 )#start if
#my $rc = system <STDIN>;
#chomp $rc;

$rc = system("/bin/date");
}#end if

else #start else
$rc = system ("Unknown Program");
}#end else

printf("Parent Process before the fork: UID = %d, PID = %d\n", $>,$$);

$pid = fork(); #fork child process

if($pid == 0) #start if
printf("PARENT Process after the fork: UID = %d, PID = %d\n",$>,$$);
} #end if
else #start else
#child process block
printf("The CHILD Process after the fork: UID = %d, PID = %d\n",$>,$$);
printf("CHILD Process exiting: UID = %d, PID = %d\n",$>,$$);
} #end else

if( $rc != 0 ) # error handling if condition
printf("Error! Unknown Program. \n");
} #end if

$SIG{ALRM} = sub { die "timeout" }; # die alarm signal to kill child process

eval #start eval
alarm 10;
sleep 2;
alarm 0;
}; #end eval

if ($@) #timeout, if program should overrun
if ($@ =~ /timeout/)
alarm 0;

print"No timeout\n";
printf("PARENT Process exiting UID = 0, PID = %d\n",%>,$$);

now the thing is that, I would like to know how use the <stdin> function in the parent process of the program ( before it has been forked) and have it output in the child process of the program ( after it has been forked) . I have tried it, but I believe its incorrect( i have not added the output just yet ).

Can anyone help me on this.. ? I would really appreciate it..

thanks. Smile

- Noob

(This post was edited by NoobPerl on Nov 25, 2011, 8:29 AM)


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives