Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

print() function hang for long time

by dengguochen2003 (Initiate)
on Feb 19, 2013 at 06:46 UTC ( #1019461=perlquestion: print w/ replies, xml ) Need Help??
dengguochen2003 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Monks, I beg your wisdom. I have below leg of code. I execute in rc3 script. When it comes to line 12 it seems the script hangs there for more than 20 hours. See detailed log information below the code. Please be aware that I execute this script in various machines without any problems. Only in this IBM machine with InReach TTY console connected I get this issue.

1 sub ptrace { 2 my ($msg, $level) = @_; 3 $msg = pdate()." ".$msg; 4 ptrace_wo_date($msg, $level); 5 } 6 7 sub ptrace_wo_date { 8 my ($msg, $level) = @_; 9 $level = defined $level ? $level : $norm_trace; 10 if ($traceLevel >= $level) { 11 if ($ttymode) { 12 print "$msg\n"; 13 } 14 if ($log_opened) { 15 print $logfh "$msg\n"; 16 } 17 } 18 } 19 20 sub plog { 21 my $msg = shift; 22 if ($ttymode) { 23 $msg = pdate()." ".$msg; 24 } 25 if ($log_opened) { 26 print $logfh "$msg\n"; 27 } 28 } 29 30 # Main part 31 32 my $pit_trace = "/tmp/pit.trace"; 33 my $cmd = "/tmp/FMinstall.sh" 34 ptrace("-I- executing: \n\t$cmd"); 35 system("$cmd > /tmp/instappcmd.out 2>&1"); 36 my $res = $? >> 8; 37 my $pitres = readFile("/tmp/instappcmd.out"); 38 unlink "/tmp/instappcmd.out"; 39 40 # log result and pit trace if any 41 ptrace(" execution trace:\n$pitres"); 42 43 if ( -f $pit_trace ) { 44 $pitres = readFile($pit_trace); 45 plog($pitres); 46 }

Below is the log from the above code. Lines 1 and 2 are print on 2/14, and it hangs there. After 20 hours when I login into the console of the machine lines 4 and later come out. From the time stamp on line 4 we can see the 3rd line of code should be executed on 2/14, then the code goes into the ptrace_wo_date() function, and comes to code on line 12, but it hangs there for 20 hours when I login on 2/15 it resumes. Then the code comes to line 45 and plog() prints the time stamp in below log line 21, which is 2/15.

My question is what is the possible reasons for the print() hangs. Why it resumes when I login on the console. I am on IBM machine with Console Access through terminal Server InReach MRV Port 3122. Appreciate your any comments on this in advance.

1 2013/02/14 16:25:20 -I- executing: 2 /tmp/FMinstall.sh 3 4 2013/02/14 16:50:12 execution trace: 5 6 Execution of FMinstall.sh ... 7 8 2013-02-14 16:25:22 INFO Stopping FM 9 2013-02-14 16:25:22 INFO FM instance name: player1 10 Last login: Thu Feb 14 16:24:16 GMT 2013 on console 11 Instance player1 is already in the STOPPED state. 12 Last login: Thu Feb 14 16:24:16 GMT 2013 on console 13 2013-02-14 16:25:23 INFO FM Stopped 14 15 -I- Stopping FM player2 instance 16 17 2013-02-14 16:25:23 INFO Stopping FM 18 2013-02-14 16:25:23 INFO FM instance name: player2 19 ... ... 20 21 2013/02/15 12:33:27 2013/02/14 16:50:12:Audit:event(2)::SYSTEM +():================================================== 22 2013/02/14 16:50:12:Audit:event(2)::SYSTEM(): Starting the Aud +it tool. 23 2013/02/14 16:50:12:Audit:event(2)::SYSTEM():================= +================================= 24 2013/02/14 16:50:12:Audit:debug(4)::RepositoryXml.parseReposit +oryFile():Reading file </usr/repository/products.xml>. 25 2013/02/14 16:50:12:Audit:debug(4)::Repository.Repository():Co +ntent of repository :

Comment on print() function hang for long time
Select or Download Code
Re: print() function hang for long time
by QM (Vicar) on Feb 19, 2013 at 08:18 UTC
    It seems that this line is causing the problem:
    system("$cmd > /tmp/instappcmd.out 2>&1");

    which expands to
    system("/tmp/FMinstall.sh > /tmp/instappcmd.out 2>&1");

    Did you check the process table for this script? Perhaps it was blocked, or otherwise required that much time to run?

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

      Hi, QM, Thank you for the comments on this issue. From the log that line you mentioned already is finished successfully.

      4 2013/02/14 16:50:12 execution trace:

      Because the time stamp in the above line is retrieved by code at line 3, and line 3 is executed after that line ( system("$cmd > /tmp/instappcmd.out 2>&1") ) you mentioned. So that line you mentioned must be already done successfully. It must hang on the line 12, which calls print function.
Re: print() function hang for long time
by soonix (Curate) on Feb 19, 2013 at 09:23 UTC
    To me it looks as if the line from print might be hanging in the output buffer. Perhaps try
    $| = 1
    at the start of your script and see if that helps.
      Hi, soonix, thank you for the comments.

      Could you explain more? What output buffer do you mean? A buffer allocated by print() function?

      Wired thing is that I monitor the execution of the script through a putty terminal and find it hangs there for a long while on 2/14 and leave it there. When I am back to it on 2/15 I find it still hangs. So I connect to the machine through the console. When I am in the console it resumes suddenly. The machine configuration is: IBM server -> InReach TTY -> terminal.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1019461]
Approved by Ratazong
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2014-09-21 10:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls