-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
73 lines (63 loc) · 1.84 KB
/
index.php
File metadata and controls
73 lines (63 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
**Getting Correct Process ID:-
<?php
//Get Operating System
$OperatingSystem = php_uname('s');
if($OperatingSystem == "Windows NT") {
//**Works only for PHP 4 and above. proc_get_status() does not return correct PID so
//work around is used as shown below..
$descriptorspec = array (
0 => array("pipe", "r"),
1 => array("pipe", "w"),
);
//proc_open — Execute a command
//'start /b' runs command in the background
if ( is_resource( $prog = proc_open("start /b " . $runPath, $descriptorspec, $pipes, $startDir, NULL) ) )
{
//Get Parent process Id
$ppid = proc_get_status($prog);
$pid=$ppid['pid'];
}
else
{
echo("Failed to execute!");
exit();
}
$output = array_filter(explode(" ", shell_exec("wmic process get parentprocessid,processid | find \"$pid\"")));
array_pop($output);
//Process Id is
$pid = end($output);
}
else if($OperatingSystem == "Linux") {
//**Works only for PHP 4 and above. proc_get_status() does not return correct PID so
//work around is used as shown below..
$descriptorspec = array (
0 => array("pipe", "r"),
1 => array("pipe", "w"),
);
//proc_open — Execute a command
//'nohup' command line-utility will allow you to run command/process or shell script that can continue running in the background
if (is_resource($prog = proc_open("nohup " . $runPath, $descriptorspec, $pipes, $startDir, NULL) ) )
{
//Get Parent process Id
$ppid = proc_get_status($prog);
$pid=$ppid['pid'];
//Process Id is
$pid=$pid+1;
}
else
{
echo("Failed to execute!");
exit();
}
}
?>
** To Kill Windows or Linux process:-
<?PHP
$OperatingSystem = php_uname('s');
if($OperatingSystem == "Windows NT") {
//'F' to Force kill a process
exec("taskkill /pid $pid /F");
}
else if($OperatingSystem == "Linux") {
exec("kill -9 $pid");
}