0

我有.exe档案。我想运行它并在一段时间后(比如说 1.5 秒后)通过终止.exe并报告time limit exceed. 我花了 2 天时间才发现这一点,但没有成功。

PS我不能使用pthread扩展。我在安装它时遇到问题。:(

编辑:我现在的问题是当我proc_terminate()$processphp 脚本停止等待run.exerun.exe仍在运行时(我可以在任务管理器中看到它)。我的 php 脚本:

<pre>
<?php

$descriptorspec = array(
    1 => array('pipe', 'w')
    );
$process = proc_open("C:/wamp/www/yet-another-online-judge/run.exe", $descriptorspec, $pipes);

if (is_resource($process)) {
    usleep(2.5*1000000); // wait 2.5 secs

    $status = proc_get_status($process);
    if ($status['running'] == true) {
        proc_terminate($process);
        echo "VERDICT : TLE\n";
    } else {
        echo "EXIT CODE : {$status['exitcode']}\n";
        echo "OUTPUT :\n";

        while (!feof($pipes[1]))
            echo fgets($pipes[1]);

        fclose($pipes[1]);
        proc_close($process);
    }
}

?>
</pre>

运行.cpp:

#include <iostream>
using namespace std;

int main() {
    cout << "1+1=3";
    while (1);
    return 0;
}

如果你不懂 C++:run.exe 输出1+1=3到标准输出,然后进入一个无限循环。

那么有没有办法真正终止 run.exe ?

4

0 回答 0