Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

The return code from Perl is not returned to the application

by ueua (Initiate)
on Nov 21, 2013 at 02:01 UTC ( [id://1063662]=perlquestion: print w/replies, xml ) Need Help??

ueua has asked for the wisdom of the Perl Monks concerning the following question:

Please could you tell us why the return code from Perl is not returned to the application that we have developed.

We developed C command that wraps Perl command to collect information from the ESX server.
Our application works as follows:

1. The daemon starts the command written in C (C command).
*There is a possibility that the daemon starts more than one process at the same time.
2. Perl command(Perl.exe or Perl script) is executed by C command , to collect information from the ESX server.
*They is a possibility that several processes of Perl command starts at the same time.
Because processes of Perl command are executed by several processes of C command(which are executed by the dameon).
3. Perl command that runs first time , collects the information from ESX sever, and export the information as a text.
Perl command that runs after that , waits for the text to be exported.
4. After (3), Perl command analyze the text, and returns necessary information for each process to the C command.
5. C command returns the infomation (4) to the daemon.

However, the process of C command often time out , and they are killed by the daemon.
The daemon monitors the child processes, and it determine to kill the process if it's timed out.

Perl script outputs the logs at the start and the end of operation.
From the logs ,we could see that the process had been finished successfully.
But, after the logs had been written, the exit code that should be returned from Perl command to C command had not been returned.
And few minutes later, the process of C command had been killed by the daemon.

We think that this problem had occurred because there were something wrong in Perl command .
Please tell us why this problem had occurred and if there are any similar cases.
As long as we have examined, we think this case is similar to the following case.
In the following case, Perl command hangs by waitpid in Windows environment .
http://stackoverflow.com/questions/12011300/perls-waitpid-and-ipcopen2-in-windows-vs-linux-unix

OS:
Microsoft Windows Server 2008 R2 Enterprise
OSver:
6.1.7601 Service Pack 1 build 7601
x64-based PC

SDK:
vSphere SDK for Perl version: 5.0
Script 'vmware-cmd.pl' version: 5.0

perl -v:
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 50 registered patches, see perl -V for more detail)<\p>

Replies are listed 'Best First'.
Re: The return code from Perl is not returned to the application
by boftx (Deacon) on Nov 21, 2013 at 02:29 UTC

    It would be helpful to have:

    • an example of how you are exiting the Perl script (i.e. are you using exit?)
    • an example of how you are spawning/forking the Perl script from your C program, and how you wait for it to finish and process the return code.

    It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

      I am sorry for the delay in my response.

      >an example of how you are exiting the Perl script (i.e. are you using exit?)
      Yes, I am using exit like folloing code.

      ---- perl script ----
      #unlock the file and output the log
      &exit_instance;
      
      #return exit code to C program.
      POSIX:_exit($ret ? EXIT_SUCCESS : EXIT_FAILURE);
      ---- perl script ----
      

      >an example of how you are spawning/forking the Perl script from your C program,
      >and how you wait for it to finish and process the return code.
      The daemon run C programs using CreateProcess() in Windows.
      And, C program run a Perl script using system().
      ---- Daemon ----
      if( TRUE != CreateProcess( NULL, commandLine, &sa, &sa, TRUE, CREATE_NEW_PROCESS_GROUP | NORMAL_PRIORITY_CLASS, NULL, NULL,
      			&StartInfo, &ProcInfo ) ) {
      	dRet = GetLastError();
      	LOGOUTPUT_ERR_WITHNUM_WIN( 0, MS_M_CREATEPROC_E, dRet );
      	return dRet;
      }
      ---- Daemon ----
      

      ---- C program ----
      #szCmd means perl command
      if (-1 == (ret = system(szCmd))) {
      	err = errno;
      	printf("Execution failure.%d\n", err);
      	return EXIT_FAILURE;
      }
      return ret;
      ---- C program ----
      
      As an image, look at the following flow.
      1. daemon -(launch)-> C program(1)
                -(launch)-> C program(2)
                -(launch)-> C program(3)
      
      2. C program(1) -(launch)-> perl script(1)
         C program(2) -(launch)-> perl script(2)
         C program(3) -(launch)-> perl script(3)
      
      3. perl script(1) -> get information from ESX server and write it to text
         perl script(2) -> wait for information about ESX server(i.e. wait until perl script(1) write a text)
         perl script(3) -> wait for information about ESX server(i.e. wait until perl script(1) write a text)
      
      4. after (3), each perl script process get information from text, and analyze it.
      
      As I already wrote, perl script outputs the logs at the start and the end of operation.
      From the logs ,we could see that the process had been finished successfully.
      But, after the logs had been written, the exit code that should be returned from Perl command to C command had not been returned.
      I really do not know, how to solve this problem.

Re: The return code from Perl is not returned to the application
by jesuashok (Curate) on Nov 21, 2013 at 03:30 UTC
    Just a thought: If you have the perl debug, you can run the perl program to execute line by line using the debug option, it will help to give more visibility for you to troubleshoot.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-03-29 07:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found