功能:
1. 利用tasklist获取进程列表,保存进数据库。
2. 进程列表显示,表格排版。点击某列表头能够按该列排序。
3. 组合查询:可按映像名称、会话名模糊搜索,内存使用范围搜索。
内存管理系统.html
<!DOCTYPE html>
<!-- 实现了组合查询 ,默认不填为查询全部-->
<html>
<head>
<title></title>
<style type="text/css">
form{
padding-left:500px;
}
span {
font-size: 120%;
color: green;
width: 120px;
text-align: left;
position: absolute;
top: 8px;
left: -50px;
}
input {
padding: 0 20px;
outline: none;
border: 1px solid #ccc;
width: 150px;
height: 30px;
border-radius: 5px;
}
li {
list-style-type: none;
padding-left: 50px;
position: relative;
}
.btn {
background-color: green;
color: white;
border: none;
font-size: 14px;
margin: 4px 2px;
cursor: pointer;
/*鼠标样式*/
border-radius: 15px;
}
</style>
</head>
<body>
<form id="two" action="http://127.0.0.1/memorySystem/memoryManagement.php" method="post">
<h1>内存管理系统--查询</h1>
<ul>
<li>
<span>映像名称:</span>
<input class="edit" type="text" name="id_search" maxlength="30" size="30"/><br>
</li>
<li>
<span>会话名:</span>
<input class="edit" type="text" name="name_search" maxlength="30" size="30"/><br>
</li>
<li>
<span>内存范围:</span>
<input class="edit" type="number" name="num1_search" maxlength="5" min="0" style="width: 50px;" /> ~
<input class="edit" type="number" name="num2_search" maxlength="5" min="0" style="width: 50px;"/><br>
</li>
</ul>
<input class="btn" type="submit" name="提交" value="查询">
<input class="btn" type="reset" name="重置" value="重填">
</form>
</body>
</html>
memoryManagement.php
<?php
//error_reporting( E_ALL&~E_NOTICE );//屏蔽警告
$con=mysql_connect("localhost","root","toor") or die("连接失败");
$db=mysql_select_db("lwy");//数据库名
$tasklist=`tasklist`;
$tasklist=explode("\n",$tasklist);//拆分为数组便于后期截取
mysql_query("truncate tasklist");
for($i=3;$i<count($tasklist)-1;$i++){
$a=substr($tasklist[$i],0,26);
$b=substr($tasklist[$i],27,8);
$c=substr($tasklist[$i],35,9);
$d=substr($tasklist[$i],62,2);
$e=trim(substr($tasklist[$i],67,8));
$split=explode(",",$e);
$joint=null;
foreach($split as $array){
$joint=$joint.$array;
}
mysql_query("insert into tasklist values('$a','$b','$c','$d','$joint')");
}
mysql_close($con);//节约系统资源
if(!isset($_GET['sort']))
{
$id=$_POST['id_search'];
$name=$_POST['name_search'];
$num1=$_POST['num1_search'];
$num2=$_POST['num2_search'];
}
else{
$sort=$_GET['sort'];
$id=$_GET['ids'];
$name=$_GET['names'];
$num1=$_GET['num1s'];
$num2=$_GET['num2s'];
}
?>
<meta charset="utf-8">
<html>
<head>
</head>
<body>
<table style="border-collapse: collapse" border="1" cellpadding="10">
<tr>
<!-- 两种方式 -->
<td> <a href="?sort=映像名称&ids=<?php echo $id ?>&names=<?php echo $name ?>&num1s=<?php echo $num1 ?>&num2s=<?php echo $num2 ?>">映像名称</a></td>
<td><?php echo "<a href=\"?sort=PID&ids=$id&names=$name&num1s=$num1&num2s=$num2\">PID</a>" ?></td>
<td><?php echo "<a href=\"?sort=会话名&ids=$id&names=$name&num1s=$num1&num2s=$num2\">会话名</a>"?></td>
<td>会话#</td>
<td><?php echo "<a href=\"?sort=内存使用&ids=$id&names=$name&num1s=$num1&num2s=$num2\">内存使用</a>"?></td>
</tr>
<?php
$con=mysql_connect("localhost","root","toor") or die("连接失败");
$db=mysql_select_db("lwy");//数据库名
if(!$num1){
$num1=0;
}
if(!$num2){
$num2=999999;
}
if(isset($_GET['sort']))
$rs=mysql_query("SELECT * FROM tasklist where 映像名称 like '$id%' and 会话名 like '$name%' and 内存使用 between $num1 and $num2 order by $sort asc");
else
$rs=mysql_query("SELECT * FROM tasklist where 映像名称 like '$id%' and 会话名 like '$name%' and 内存使用 between $num1 and $num2");
while($row=mysql_fetch_array($rs)){
?>
<tr>
<td>
<?php echo $row[0];?>
</td>
<td>
<?php echo $row[1];?>
</td>
<td>
<?php echo $row[2];?>
</td>
<td>
<?php echo $row[3];?>
</td>
<td>
<?php echo number_format($row[4])."k";?>
</td>
</tr>
<?php
}
?>
</table>
</body>