in reply to Windows process suspend

G'day gautamparimoo,

According to the Win32::Process::Kill documentation, GetHandle returns an array. I expect that calling it in scalar context will return 1 (in your code here). Subsequently, you call "SuspendProcess(1);" which is probably responsible for the crash. The documentation has the code you need.

-- Ken

Replies are listed 'Best First'.
Re^2: Windows process suspend
by gautamparimoo (Beadle) on Apr 24, 2013 at 09:28 UTC

    the documentation has given this line:

    Suspend(@Handles); or Suspend($Handle);

    So what am I exactly doing wrong?

    One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man. -Elbert Hubbard

      gautamparimoo:

      You want to kill specific processes. Each process ID is a number referring to a job. So you need to determine which process number you want to kill. It looks like you have things in hand to that point. But when you get the handles for the threads, you've got a bug. Since GetHandles returns a *list* of handles, you'll need to do something like:

      use strict; use warnings; use Win32::Process::Kill; my $pids = $ARGV[0]; # Get *all* the handles returned my @handles = GetHandle($pids); print scalar(@handles), " handles returned\n"; # We'll just suspend the first one: my $handle = $handles[0]; SuspendProcess($handle);

      Note: I'm on a linux box right now, so I can't test things out at the moment, but after reviewing the docs, that's what I'm expecting.

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.

        I think the problem is with use Win32::Process::Kill; as if i print anything after it that does not get printed and it crashes.Secondly in the documents its shown as:

        @Handles = GetHandle(@pids); or ($handle) = GetHandle($pid);

        So I cannot make out the problem. If anybody on Windows please explain?

        One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man. -Elbert Hubbard