1
Name:
Anonymous
2013-07-25 18:55
Hi /prog/,
I want to re-learn C the right way.
When I was in college I took a bunch of courses (data structures, ADTs, algorithms) but I don't think I gained a deep knowledge of C.
What are some good books or resources on modern C usage (K&R is pretty dated)?
I'd like to do some HPC later in my life and I need to start somewhere.
38
Name:
Anonymous
2013-07-28 17:43
>>37
You cannot discern a php programmer from a troll.
For example:
I want to create a daemon/Linux service. Here is an example of how to run a process that has "throttle control"
// You must set these
//
// max_execution_time = 0
// max_input_time = 0
function doProcess() {
echo "Start"."\n";
usleep(10000);
echo "Stop"."\n";
return false;
}
function manageProcess() {
// Setup data
$runsPerMinute = 200;
$maxMinuteAverage = 5;
$waitIfNotWorking = 120; // seconds
// Conversion
$microsPerSecond = 1000000;
// Statistical Info
$currentMinute = 0;
$minute = -1;
$countPerMinute = array();
$sumPerMinute = array();
// Totals
$totalProcessTime = 0;
$totalCounts = 0;
while (true) {
$timestart = microtime();
$performedWork = doProcess();
$timeend = microtime();
if (!$performedWork) {
// Statistical Info
$currentMinute = 0;
$minute = -1;
$countPerMinute = array();
$sumPerMinute = array();
sleep($waitIfNotWorking);
} else {
$ts = split(" ",$timestart);
$te = split(" ",$timeend);
$te[0] = ($te[0] * $microsPerSecond) - ($ts[0] * $microsPerSecond);
$te[1] = ($te[1] - $ts[1]) * $microsPerSecond;
$processTime = $te[0] + $te[1];
if (date("i")<>$minute) { // We are NOT in the same minute
// Reset the new minute
$minute = date("i");
$currentMinute = ($currentMinute+1) % $maxMinuteAverage;
// Remove Statistical Information from the minute we are expiring.
if (isset($countPerMinute[$currentMinute])) {
$totalProcessTime = $totalProcessTime - $sumPerMinute[$currentMinute];
$totalCounts = $totalCounts - $countPerMinute[$currentMinute];
}
$countPerMinute[$currentMinute] = 0;
$sumPerMinute[$currentMinute] = 0;
}
$countPerMinute[$currentMinute] = $countPerMinute[$currentMinute] + 1;
$sumPerMinute[$currentMinute] = $sumPerMinute[$currentMinute] + $processTime;
$totalCounts = $totalCounts + 1;
$totalProcessTime = $totalProcessTime + $processTime;
$averageRuntime = round($totalProcessTime / $totalCounts);
$waitTime = (($microsPerSecond*60) / $runsPerMinute) - $averageRuntime;
usleep($waitTime);
}
}
}
manageProcess();
This shit will happily eat away all your memory. Is he serious or not?