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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



NoobPerl
New User

Nov 25, 2011, 8:17 AM

Post #1 of 1 (253 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..

[perl]

#!/usr/bin/perl

#start main method
main:
{
#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

#Message
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",$>,$$);
sleep(5);
printf("CHILD Process exiting: UID = %d, PID = %d\n",$>,$$);
exit(0);
} #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/)
{
print"Timeout\n";
alarm 0;
exit(0);
}

}
else{
print"No timeout\n";
}
}
printf("PARENT Process exiting UID = 0, PID = %d\n",%>,$$);
[/perl]

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