Professional Web Applications Themes

Win32::Process, SetProcessAffinityMask for an existing process =perl crash - PERL Modules

Hi! Was planning to use Win32::Process to set the ProcessAffinityMask of some processes but this lead to pure and simple crash of perl.exe. This is not a credential problem as I can set the process affinity if I spawn a "process.exe" command to set the affinity. Also, the process affinity is correctly set to the expected value... Seems the crash occurs just after. Here is a sample code causing a perl.exe crash (for example using activeperl 5.6 or 5.8 (latest) on Windows 2000, XP or 2003) : ------------------ use strict; use Win32::Process; use Win32; my $obj; my $pid=2216; my $iflags; ...

  1. #1

    Default Win32::Process, SetProcessAffinityMask for an existing process =perl crash

    Hi!

    Was planning to use Win32::Process to set the ProcessAffinityMask of
    some processes but this lead to pure and simple crash of perl.exe.

    This is not a credential problem as I can set the process affinity if I
    spawn a "process.exe" command to set the affinity.

    Also, the process affinity is correctly set to the expected value...
    Seems the crash occurs just after.

    Here is a sample code causing a perl.exe crash (for example using
    activeperl 5.6 or 5.8 (latest) on Windows 2000, XP or 2003) :
    ------------------
    use strict;

    use Win32::Process;
    use Win32;

    my $obj;
    my $pid=2216;
    my $iflags;


    Win32::Process::Open($obj,$pid,$iflags) or die;


    my $processAffinityMask;
    my $systemAffinityMask;

    $obj->GetProcessAffinityMask($processAffinityMask, $systemAffinityMask)
    or die;

    $obj->SetProcessAffinityMask($processAffinityMask) or die;
    -------------------



    I also experience strange behavior while using Win32::Daemon to make my
    perl scripts act as an NT service (under Windows 2003 my script
    unexpectedly says he receives SERVICE_STOP signals. And stops..).

    Am feeling I should abandon perl to do system tasks on Windows systems.
    Too bad cause I invested quite some time to get knowledgeable in perl...
    And I must also improve in Java for weblogic stuff. So am not willing
    to start learning yet another language like VB/.NET..

    Rgds,
    Chacallot.
    chacallot Guest

  2. #2

    Default Re: Win32::Process, SetProcessAffinityMask for an existing process = perl crash


    "chacallot" <chachallotfree.fr>
    ..
    >
    > Here is a sample code causing a perl.exe crash (for example using
    > activeperl 5.6 or 5.8 (latest) on Windows 2000, XP or 2003) :
    > ------------------
    > use strict;
    >
    > use Win32::Process;
    > use Win32;
    >
    > my $obj;
    > my $pid=2216;
    > my $iflags;
    >
    >
    > Win32::Process::Open($obj,$pid,$iflags) or die;
    >
    >
    > my $processAffinityMask;
    > my $systemAffinityMask;
    >
    > $obj->GetProcessAffinityMask($processAffinityMask, $systemAffinityMask)
    > or die;
    >
    > $obj->SetProcessAffinityMask($processAffinityMask) or die;
    > -------------------
    That works fine for me on Windows2000 using MinGW-built perl 5.8.8 and
    MinGW-built perl 5.6, but like you, I find it crashes with ActiveState perl
    when SetProcessAffinityMask() gets called.

    I don't know why it crashes with perl built using a Microsoft compiler (also
    crashes with my VC7-built perl), and yet causes no problem with MinGW-built
    perl.

    If you don't find the answer here I would try posting to
    comp.lang.perl.misc - and if that fails, try the perl-win32-users mailing
    list hosted by ActiveState.

    Cheers,
    Rob


    Sisyphus Guest

  3. #3

    Default Re: Win32::Process, SetProcessAffinityMask for an existing process= perl crash

    chacallot wrote:
    > Hi!
    >
    > Was planning to use Win32::Process to set the ProcessAffinityMask of
    > some processes but this lead to pure and simple crash of perl.exe.
    >
    > This is not a credential problem as I can set the process affinity if I
    > spawn a "process.exe" command to set the affinity.
    >
    > Also, the process affinity is correctly set to the expected value...
    > Seems the crash occurs just after.
    >
    > Here is a sample code causing a perl.exe crash (for example using
    > activeperl 5.6 or 5.8 (latest) on Windows 2000, XP or 2003) :
    > ------------------
    > use strict;
    >
    > use Win32::Process;
    > use Win32;
    >
    > my $obj;
    > my $pid=2216;
    > my $iflags;
    >
    >
    > Win32::Process::Open($obj,$pid,$iflags) or die;
    >
    >
    > my $processAffinityMask;
    > my $systemAffinityMask;
    >
    > $obj->GetProcessAffinityMask($processAffinityMask, $systemAffinityMask)
    > or die;
    >
    > $obj->SetProcessAffinityMask($processAffinityMask) or die;
    > -------------------
    >
    >
    >
    > I also experience strange behavior while using Win32::Daemon to make my
    > perl scripts act as an NT service (under Windows 2003 my script
    > unexpectedly says he receives SERVICE_STOP signals. And stops..).
    >
    > Am feeling I should abandon perl to do system tasks on Windows systems.
    > Too bad cause I invested quite some time to get knowledgeable in perl...
    > And I must also improve in Java for weblogic stuff. So am not willing
    > to start learning yet another language like VB/.NET..
    >
    The Problem is in the C/C++ source code. It uses a pointer to the
    function defined in kernel32.dll. I changed the source to use the
    SetProcessAffinityMask API directly and now there is no crash.

    So I suggest to ask the owner of the module to change it.

    regards,
    Reinhard
    Reinhard Pagitsch Guest

  4. #4

    Default Re: Win32::Process, SetProcessAffinityMask for an existing process= perl crash

    Reinhard Pagitsch wrote:
    > chacallot wrote:
    [ about Win32::Process::SetProcessAffinityMask crashing perl]
    > The Problem is in the C/C++ source code. It uses a pointer to the
    > function defined in kernel32.dll. I changed the source to use the
    > SetProcessAffinityMask API directly and now there is no crash.
    Could you please elaborate or provide a patch? As I read it (which could
    of course be wrong), your statement suggests that there is a
    'SetProcessAffinityMask' outside of kernel32.dll.

    Thomas

    --
    $/=$,,$_=<DATA>,s,(.*),$1,see;__END__
    s,^(.*\043),,mg,_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
    $_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
    '%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
    print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e. r^.>l^..>k^.-
    Thomas Kratz Guest

  5. #5

    Default Re: Win32::Process, SetProcessAffinityMask for an existing process= perl crash

    Hello Thomas,



    Thomas Kratz wrote:
    > Reinhard Pagitsch wrote:
    >> chacallot wrote:
    >
    > [ about Win32::Process::SetProcessAffinityMask crashing perl]
    >
    >> The Problem is in the C/C++ source code. It uses a pointer to the
    >> function defined in kernel32.dll. I changed the source to use the
    >> SetProcessAffinityMask API directly and now there is no crash.
    >
    > Could you please elaborate or provide a patch? As I read it (which could
    > of course be wrong), your statement suggests that there is a
    > 'SetProcessAffinityMask' outside of kernel32.dll.
    I think you missunderstood what I wrote. What I have done is not using
    LoadLibrary() to import SetProcessAffinityMask function with
    GetProcAddress(). I used the (API?) function as described in the
    Platform SDK:
    BOOL SetProcessAffinityMask( HANDLE hProcess, DWORD_PTR
    dwProcessAffinityMask);

    The patch:
    In the Process.hpp:
    class cProcess
    {

    .....

    BOOL _SetProcessAffinityMask( DWORD dwProcessAffinityMask )
    {
    BOOL ret;
    //if(pSetProcessAffinityMask)
    ret = SetProcessAffinityMask( ph, dwProcessAffinityMask );
    if(!ret) return GetLastError();
    return ret;
    //return FALSE;
    }
    ....

    };
    (The original code is commented out with //.)


    And in the Process.xs:
    BOOL
    SetProcessAffinityMask(cP,processAffinityMask)
    cProcess *cP
    DWORD processAffinityMask
    CODE:
    RETVAL = cP->_SetProcessAffinityMask(processAffinityMask);
    OUTPUT:
    RETVAL


    Thats all, now I do not get a crash of my Perl v5.6.1.



    regards,
    Reinhard
    Reinhard Pagitsch Guest

  6. #6

    Default Re: Win32::Process, SetProcessAffinityMask for an existing process= perl crash

    Hello Reinhard,

    Reinhard Pagitsch wrote:
    > I think you missunderstood what I wrote.
    Yes, I was almost sure I did :-)
    > What I have done is not using
    > LoadLibrary() to import SetProcessAffinityMask function with
    > GetProcAddress(). I used the (API?) function as described in the
    > Platform SDK:
    > BOOL SetProcessAffinityMask( HANDLE hProcess, DWORD_PTR
    > dwProcessAffinityMask);
    Ah, I see. I don't understand why the LoadLibrary is done at all. Every
    extension is linked against kernel32.lib anyway, which results in the
    functions being called dynamically through kernel32.dll.

    Thanks,
    Thomas

    --
    $/=$,,$_=<DATA>,s,(.*),$1,see;__END__
    s,^(.*\043),,mg,_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
    $_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
    '%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
    print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e. r^.>l^..>k^.-
    Thomas Kratz Guest

  7. #7

    Default Re: Win32::Process, SetProcessAffinityMask for an existing process = perl crash

    Thx for your answers.

    Emailed info about this thread to the module author.
    Hope he'll be able to notice it in all the spam he's probably getting.

    His email is an activestate.com. Lets see how active those are...

    Regards,
    Chacallot.

    chacallot@gmail.com Guest

Similar Threads

  1. Win32::Process Kill Process in Windows ME
    By Stefan Mueller in forum PERL Modules
    Replies: 3
    Last Post: April 15th, 07:35 PM
  2. Q: Win32::Process::Info
    By Reinhard Pagitsch in forum PERL Modules
    Replies: 0
    Last Post: June 16th, 07:33 AM
  3. Win32::Process::Info and CreationDate
    By Scott Beinhower in forum PERL Modules
    Replies: 3
    Last Post: February 1st, 06:16 AM
  4. LOST - Win32::Process
    By RL in forum PERL Modules
    Replies: 3
    Last Post: January 30th, 12:07 AM
  5. Understaing Win32::Process::Create
    By Mike in forum PERL Modules
    Replies: 1
    Last Post: October 29th, 12:33 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139