Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9143295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:59:13+00:00 2026-06-17T09:59:13+00:00

I am writing a function in perl which will kill a process given its

  • 0

I am writing a function in perl which will kill a process given its PID.

sub ShutPidForWindows()
{
    require Win32::Process;
    $PID = 1234;
    $count = 0;
    $ReturnStatus = 0;
    $ExitCode = 0 ;

    if ($PID == 0)
    {
        return ($ReturnStatus);
    }

    Win32::Process::KillProcess($PID, $ExitCode);
    print "PID = ".$PID."\n";
    print "Return Code = ".$ExitCode."\n";

    if ($ExitCode)
    {
        $ReturnStatus = 1;
    }
    else
    {
        $ReturnStatus = 2;
    }
    return ($ReturnStatus);
}

when this function is executed it always returns 2. Even though the process 1234 does not exists.

The o/p I get is:

PID = 1234
Return Code = 0

Perl Doc says that ExitCode will be populated by the exit code returned by the process. Then ExitCode should be 1.

Am I doing anything wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:59:14+00:00Added an answer on June 17, 2026 at 9:59 am

    The problem is that you are using require instead of use to load the module. Sometimes this is OK, but you should always follow the examples in the module’s documentation.

    You must also always use strict and use warnings at the top of every Perl program you write. This will make it necessary to declare all of your variables, which should be done as close as possible to their first point of use. These measures will reveal many errors that you may otherwise overlook, and is especially important when you are asking others for help with your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently writing a function what would create a zip file, which will be
I'm writing a function which will drop a table if it already exists. It
I'm writing a function, which determine the number of useful bits of a 16
I'm writing a GUI app on gtk2 perl. There is a table which show
I am writing a Perl/Tk script which displays Excel worksheets using the ss2tk example
Writing a function in Lua, which creates two tables. I want the tables to
I was writing a function to figure out if a given system of linear
I'm writing a function in R that will take the path name of a
I'm writing some tests in Perl which have a fair amount of set up.
Hey I thought about writing a function that prompts me in certain situations (perl

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.