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 6918831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:54:37+00:00 2026-05-27T09:54:37+00:00

I am trying to run an application inside a Perl script using system() .

  • 0

I am trying to run an application inside a Perl script using system(). The application I’m running gets stuck sometimes (it enters some kind of infinite loop). Is there a way I can know if this application is stuck and kill it to continue with the Perl script?

I’m trying to do something like this:

start testapp.exe;
if(stuck with testapp.exe) {
    kill testapp.exe;
}
  • 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-05-27T09:54:37+00:00Added an answer on May 27, 2026 at 9:54 am

    Determining if “it is stuck in infinite loop” is called Halting Problem and is undecidable.

    If you want to kill it, you will have to fork the application using fork and then kill it from the other fork, if it is going for too long.

    You can determine if the proccess is going for too long by this

    use POSIX ":sys_wait_h";
    waitpid($pid, WNOHANG)>0 #waitpid returns 0 if it still running
    

    at least, according to this manual page

    I am not sure how well it works on various systems, you can try it out.

    Not a direct answer, but I can recommend using forks module if you want to fork with ease, but it works only on UNIX systems (not windows).


    OK, more helping code 🙂 It works in UNIX, according to perlfork perldoc, it should work on Windows exactly the same way.

    use warnings;
    use strict;
    
    use POSIX ":sys_wait_h";
    my $exited_cleanly;                 #to this variable I will save the info about exiting
    
    my $pid = fork;
    if (!$pid) {
         system("anything_long.exe");        #your long program 
    } else {
         sleep 10;                           #wait 10 seconds (can be longer)
         my $result = waitpid(-1, WNOHANG);  #here will be the result
    
         if ($result==0) {                   #system is still running
             $exited_cleanly = 0;            #I already know I had to kill it
             kill('TERM', $pid);             #kill it with TERM ("cleaner") first
             sleep(1);                       #wait a bit if it ends
             my $result_term = waitpid(-1, WNOHANG);
                                             #did it end?
    
             if ($result_term == 0) {        #if it still didnt...
                 kill('KILL', $pid);         #kill it with full force!
             }  
         } else {
             $exited_cleanly = 1;            #it exited cleanly
         }  
    }
    
    #you can now say something to the user, for example
    if (!$exited_cleanly) {...} 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to run an applescript inside my Cocoa app using the system(); function
I was trying to run my application and check for some output on the
I am trying to run some unit tests in a C# Windows Forms application
I am trying to run a command-line command from inside my Delphi application. ShellExecute(Form1.Handle,
I am trying to run an application that normally works when I install on
I am working on a UNIX box, and trying to run an application, which
I am trying to a run an application with Hibernate annotation. I am getting
I am trying to run a simple multiple processes application in Python. The main
I am trying to run a simple SQLITE application on Windows Mobile developed with
We are trying to run shark on our iphone application. However, in the analyzed

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.