Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Win32::Process - Suspend/Resume/Kill NOT working with binary of par packer?

by Dirk80 (Monk)
on Feb 14, 2011 at 16:11 UTC ( #888023=perlquestion: print w/replies, xml ) Need Help??
Dirk80 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

Here a small program "counter.pl" I want to run as child process.

#!/usr/bin/perl use strict; use warnings; $|=1; print "$_\n" and select(undef,undef,undef,0.1) for 1 .. 1000;

The following code is working:

#!/usr/bin/perl use strict; use warnings; use Win32::Process; use Win32; sub ErrorReport { print Win32::FormatMessage( Win32::GetLastError() ); } my $ProcessObj; Win32::Process::Create($ProcessObj, "C:\\Perl\\bin\\perl.exe", "perl counter.pl", 1, CREATE_NEW_PROCESS_GROUP, ".")|| die ErrorReport(); $ProcessObj->Suspend(); sleep(1); $ProcessObj->Resume(); sleep(1); $ProcessObj->Suspend(); sleep(1); $ProcessObj->Resume(); sleep(3); $ProcessObj->Kill(0);

The process is running for a second. Then suspended, then running again for 3 seconds and then killed.

Now I made an exe out of "counter.pl" as follows:

pp -o counter.exe counter.pl

And now I am calling the "counter.exe".

#!/usr/bin/perl use strict; use warnings; use Win32::Process; use Win32; sub ErrorReport { print Win32::FormatMessage( Win32::GetLastError() ); } my $ProcessObj; Win32::Process::Create($ProcessObj, ".\\counter.exe", "counter", 1, CREATE_NEW_PROCESS_GROUP, ".")|| die ErrorReport(); $ProcessObj->Suspend(); sleep(1); $ProcessObj->Resume(); sleep(1); $ProcessObj->Suspend(); sleep(1); $ProcessObj->Resume(); sleep(3); $ProcessObj->Kill(0);

But the code is not working anymore. The process is NOT suspended, NOT resumed and NOT killed.

Why???

Is Win32::Process NOT working with a binary file created by "pp" or am I doing something wrong?

Thank you for your help.

Dirk

Replies are listed 'Best First'.
Re: Win32::Process - Suspend/Resume/Kill NOT working with binary of par packer?
by Anonyrnous Monk (Hermit) on Feb 14, 2011 at 19:48 UTC

    My guess would be that the Perl script is run in a separate process.  The wrapper binary (counter.exe) most likely just unpacks the par package, and then runs the Perl binary...  Check the PIDs and you'll know.

Re: Win32::Process - Suspend/Resume/Kill NOT working with binary of par packer?
by Anonymous Monk on Feb 15, 2011 at 01:23 UTC

      Thank you very much. This is great help.

      But nevertheless I'm not sure how to get it to run. I now set PAR_GLOBAL_DEBUG as follows in the script:

      $ENV{'PAR_GLOBAL_DEBUG'} = 1;

      So I get a lot of output and I know a bit where it is unpacked.

      But how can I get the values of PAR_0 (the most interesting value for me) and PAR_TEMP. Always after I start "counter.exe" and then I want to see the values of PAR_0 and PAR_TEMP they are undefined. Why?

      I think I have to know where "counter.exe" is unpacked before executing it. So I could call the unpacked perl script with the unpacked perl interpreter in the Win32::Process::Create. But I have no idea how to do it.

      I read the documentation you told me. But still I don't know how to do it.

      And then still another question. Am I right if I say the extracted perl script in the temp directory is a child process of the "counter.exe"? If yes then I do not understand why it is not working. Because I call Win32::Process::Create with the parameter CREATE_NEW_PROCESS_GROUP. So if a kill or suspend is done it should also take into account the child processes.

      As you can see I'm totally confused how to solve it. So I hope that you can help me and give me some more hints.

      Thank you.

Re: Win32::Process - Suspend/Resume/Kill NOT working with binary of par packer?
by sundialsvc4 (Abbot) on Feb 15, 2011 at 15:16 UTC

    /me nods...

    My guess is that, in your second example, you are suspending and resuming a child process which has spawned what is to you a grandchild process, and that it is the grandchild that is doing the work (and, as grandchildren always do, is paying absolutely no attention to you unless you have a goodie in your hand with which to spoil them).

      Yeah, and?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://888023]
Approved by Corion
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2018-07-23 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (459 votes). Check out past polls.

    Notices?