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

  • SEARCH
  • Home
  • 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 8503819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:51:38+00:00 2026-06-11T01:51:38+00:00

I am executing javaw with an infinite looping java file using this: $descriptorspec =

  • 0

I am executing javaw with an infinite looping java file using this:

$descriptorspec = array(
                                0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
                                1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
                                2 => array("pipe", "w") // stderr is a file to write to
                        );

 // e.x. $javaCmd = "java -cp "../Fully Diversified Sequences of Sets" SuperEasyProblemSolution2 > /dev/null 2>&1 < h.in"
$proc = proc_open($javaCmd, $descriptorspec, $pipes);//, $cwd, $env);
 stream_set_blocking($pipes[0], 0) ;

 $status = proc_get_status($proc);  
 var_dump($status);
  $timeOut = 5;
  $currentSecond = 0;

  while( $currentSecond < $timeOut ) {
        echo '<br/>';
        sleep(1);
        $currentSecond = $currentSecond +1;
        if( ! $status["running"] )
        {
            echo 'process exited before timing out'; // Process must have exited, success!
            return;
        }
        $status = proc_get_status($proc);
        var_dump($status);
  } // end while
  if($currentSecond  == $timeOut)
  {
      // kill KILL KILL!
      exec("taskkill /PID ".$status['pid']);
  }

On the first call to proc_get_status, running attribute returns true. On the second call (one second later) to proc_get_status, running returns false. The application javaw.exe is still running, however ( I call proc_get_status in a while loop that will eventually timeout.)

My goal is to taskkill the program after the timeout has expired. See a similar question here.
I am running on Win7 64 bit, PHP 5.3

Var dump on $status: (Note; I tried applying stream_set_blocking($pipes[0], 0) ;, same issue)

Before entering timeout loop:

    array(8) { 
["command"]=> string(157) "java -cp "../Fully Diversified Sequences of Sets" SuperEasyProblemSolution2 /dev/null 2>&1 < h.in" 
["pid"]=> int(3264) 
["running"]=> bool(true) 
["signaled"]=> bool(false) 
["stopped"]=> bool(false) 
["exitcode"]=> int(-1) 
["termsig"]=> int(0) 
["stopsig"]=> int(0) 
} 

After first iteration/sleep(1):

    array(8) { 
["command"]=> string(157) "java -cp "../Fully Diversified Sequences of Sets" SuperEasyProblemSolution2 /dev/null 2>&1 < h.in" 
["pid"]=> int(3264) 
["running"]=> bool(false) 
["signaled"]=> bool(false) 
["stopped"]=> bool(false) 
["exitcode"]=> int(1) 
["termsig"]=> int(0) 
["stopsig"]=> int(0) 
} 
    process exited before timing out

After testing, it appears that $status[‘pid’] is different than the pid for javaw.exe under Windows’ Resource Monitor.

  • 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-11T01:51:40+00:00Added an answer on June 11, 2026 at 1:51 am

    Although we couldnt pinpoint the issue with proc_get_status returning the incorrect boolean, we were able to find a good work-around (for Unix), using

    if (file_exists("/proc/".$status["pid"])) {
    // process still running
    }

    to check if the process was still running or not.

    Here is the full code excerpt:

    $proc = proc_open($javaCmd, array(array("pipe", "r"), array("pipe", "w"), array("pipe", "w")), $pipes);
    
    $status = proc_get_status($proc);
    
    if($status["pid"] === false)
    {
        // Process did not execute correctly
    }
    else
    {
            $timeOut = 0;
            $forceKill = true;
    
            while($timeOut < $timeLimit)
            {
                $timeOut++;
                sleep(1);
                echo 'Timeout is at '.$timeOut.' and timelimit: '.$timeLimit.'<br/>';
    
                if (file_exists("/proc/".$status["pid"])) {
                // process still running
                }
                else
                {
                    echo 'Finished running after '.$timeOut.' seconds<br/>';
                    $forceKill = false;
                    break;
                }
    
            }
            if($forceKill == true)
            {
                echo ' Manual killing pid '.$status['pid'];
                exec("sudo kill ".$status['pid']);
                $runTime = $timeLimit;
            }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am connecting to a MySQL database using Java. I am executing this query:
As we all know Java program will start executing from the public static void
I am trying to work on a project which involves running/executing the java file
I believe this is how I can compile and run a file that uses
I have this error while executing a java class to update a mysql db
I am executing an application using Java application (Runtime.get...) but now before running the
Getting this error: java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:200) at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
I'm executing the java binary from one of my classes, and a ClassNotFoundException gets
I am executing groovy script in java: final GroovyClassLoader classLoader = new GroovyClassLoader(); Class
I'm executing a shell pipeline from a java program - it'll be something like

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.