Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with fork()

Status
Not open for further replies.

mwhamilton

Technical User
Jan 28, 2002
11
US
Hi,
I am spawning a bunch of child processes with fork, and I need some help with performing some actions inside the child processes. After I fork, I need to switch machines, switch directories, and then call a script. The problem is that when I change hosts, it changes it in the xterm that I have called the original forking script. I basically need the freedom to have my child process change hosts, change directories, and run a script without the original terminal ever knowing the difference. But, I do need the output of the script to print to the STDOUT. Any help would be greatly appreciated!



for ( $i=0; $i<=$#commands; $i++ ) #for number of commands
{
$cmd = $commands[$i];

# HIT MAXIMUM? WAIT FOR A CHILD TO FINISH
if ( $count >= $maxcount )
{
# WAIT FOR A CHILD
if ( ($pid = wait()) != -1 )
{
$count--;
&Finish($i, $count, $pid);
}
}
check:
$host = &chk_avail();
if(!$host){
print&quot;All machines currently busy. Waiting for available machine...\n&quot;;
sleep 5;
goto check;
}

# START A NEW CHILD
if ( ( $pid = fork()) == 0 )
{
CHILD:
$machines_in_use{$host} = $pid;
#Need Help with these system commands#
rsh $hew_host;
cd ~/project_dir;
script.pl
exit(1);

}
else
{
# PARENT
$children{$pid} = $cmd;
&Started($i, $count, $pid);
$count++;
}
}
 
Looks like you're almost there with it. Have a look at the rcmd command instead of rsh, you'll need to call it inside the Perl function system() but I think it will do what you want. Mike
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top