中的wchar
行(文字)/proc/$pid/io
可以为您提供有关该dd
过程的准确信息。只要更改,您dd
仍在工作!
这是一个整洁的小PHP脚本,它可以保存,然后与执行php filename.php
过程中dd
,显示写入的字节。看的好的效益/proc/$pid/io
超过kill -USR1 $(pidof dd)
是,你不必终端,这并不总是一个选项之间进行切换。
<?php
/** Time between refreshs in seconds */
$refresh = 1;
/**
* Start of Script
*/
if (!($pid = exec('pidof dd')))
exit("no dd running\n");
$history = array();
$break_ms = $refresh * 1000000;
$start_time = exec("ls -ld /proc/$pid --time-style=+\"%s\" | egrep -o [0-9]{10}");
fprintf(STDOUT, "PID: %s\n", $pid);
fprintf(STDOUT, "START TIME: %s\n\n", date("Y-m-d H:i:s", $start_time));
while (true) {
if (isset($curr))
array_push($history, $curr);
if (count($history) > 10) array_shift($history);
$oldest = reset($history);
$latest = end($history);
/**
* get number of written bytes from /proc/$pid/io
*/
#if (!($curr = exec("cat /proc/$pid/io | grep ^write_bytes | sed 's/write_bytes: //g'")))
# break;
/* prepare proc_open() parameter */
$descriptorspec = array(
0 => array('pipe', 'r'), // stdin
1 => array('pipe', 'w'), // stdout
2 => array('pipe', 'w'), // stderr
);
$process = proc_open("cat /proc/$pid/io | grep ^write_bytes | sed 's/write_bytes: //g'", $descriptorspec, $pipes);
if (!is_resource($process)) break;
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
proc_close($process);
if (!empty($stderr)) break;
$curr = trim($stdout);
/**
* caculate elapsed time from start */
$time_elapsed = time() - $start_time;
/**
* avg speed since start */
$avg = $time_elapsed > 0 ? round($curr / $time_elapsed) : 0;
/**
* avg speed of last 10 updates */
if (count($history) > 0)
$speed = human_file_size(round(($latest - $oldest) / count($history) / $refresh));
$output = sprintf("\rBYTES WRITTEN: %s [%s] :: CURRENT: %s/s :: AVERAGE: %s/s :: ELAPSED: %s", $curr, human_file_size($curr), isset($speed) ? $speed : 0, human_file_size($avg), gmdate("H:i:s", $time_elapsed));
printf("%s%s", $output, str_repeat(" ", exec("tput cols") - strlen($output)));
usleep($break_ms);
}
fprintf(STDOUT, "\ndd has finished!\n\n");
function human_file_size($size,$unit="") {
if( (!$unit && $size >= 1<<30) || $unit == "GB")
return number_format($size/(1<<30),2)." GB";
if( (!$unit && $size >= 1<<20) || $unit == "MB")
return number_format($size/(1<<20),2)." MB";
if( (!$unit && $size >= 1<<10) || $unit == "kB")
return number_format($size/(1<<10),2)." kB";
return number_format($size)." bytes";
}
dd ... bs=16M
考虑到您的RAM,磁盘大小和速度,这是我的建议。