Getting Linux process status from /proc
Linux /proc file system contains lots of information about the system and all running processes.
 This article discusses one of the main files /proc/<pid>/stat which gives information about current running process.
 I could not find good documentation for this file.
This article is written after some search on the network and looking at the source.
the stat file is an ascii file with one line of numbers and characters.
 Fields are seperated with spaces.
 
 The fields are as follows:
 1. pid
 2. Executable name (usually given in parathesis)
 3. state (R - running, S - sleeping, D - uninterruptible wait, Z - zombie, T - traced or stopped)
 4. effective user id
 5. effective group id
 6. Parrend pid
 7. pgrp of the process
 8. Session id of the process
 9. tty used
 10. tpgid (I could not find documentation for this field meaning)
 11. flags of process (could not find documentation for flags meaning)
 12. Number of minor faults
 13. Number of minor faults with childs
 14. Number of major faults
 15. Number of major faults with childs
 16. Usermode jiffies
 17. Kernel mode jiffies
 18. Usermode jiffies with childs
 19. Kernel mode jiffies with childs
 20. Process next timeslice
 21. Standard nice value plus 15
 22. Time in jiffies of next timeout
 23. Time before next SIGALRM is sent
 24. Time the process started after system bot
 25. Virtual memory size
 26. Resident set size
 27. Current limit in bytes on resident set size
 28. Start address of code
 29. End address of code
 30. Stack address
 31. Value of ESP
 32. Value of EIP
 33. Bitmap of pending signals
 34. Bitmap of blocked signals
 35. Bitmap of ignomed signals
 36. Bitmap of catched signals
 37. Could not find documentation for this field
 39. scheduler (Could not find documentation for meaning)
 40. scheduler priority
function RecursiveDelete($num) {
	global $commentstbl;
	$query = "SELECT num FROM $commentstbl WHERE ancestor='$num'";
	$result = DoQuery($query, __LINE__);
	if($result->num_rows == 0)
		return;	/* end of recursive call */
	while($line = $result->fetch_assoc()) {
		$n = $line['num'];
		$query = "DELETE FROM comments WHERE num=$n";
		$newresult = DoQuery($query, __LINE__);
		RecursiveDelete($n);
	}
}
function GetTimeStr($hour, $min, $sec, $month, $day, $year) {
	global $timeoffset;
	$time = mktime($hour, $min, $sec, $month, $day, $year, 0);
	$time += ($timeoffset * 3600);	/* add time offset in seconds */
	
	$str = date("d/m/Y  H:i:s", $time);
	return $str;
}
/*
 | AddLinks:
 | Replace URL's in string with links
 */
function AddLinks($string) {
  $string = preg_replace("/(^|[^=\"\/])\b((\w+:\/\/|www\.)[^\s<]+)".
			 "((\W+|\b)([\s<]|$))/i", "$1
$2$4",
			 $string);
  return preg_replace("/href=\"www/i", "href=\"http://www", $string);
  //  $txt = preg_replace( "/(?\s]+)/i", "
\\0", $txt );
  //  "
}
/*
 | Replace special codes in messages
 */
function SpecialCodes($str) {
	$str = stripslashes($str);
	$str = str_replace('<', '<', $str);
	$str = str_replace('|code|', '
', $str);
	$str = str_replace('|CODE|', '', $str);
	$str = str_replace('|ECODE|', '
', $str);
	$str = str_replace('|ecode|', '
', $str);
	$str = str_replace('|b|', '
', $str);
	$str = str_replace('|B|', '', $str);
	$str = str_replace('|eb|', '', $str);
	$str = str_replace('|EB|', '', $str);
	$str = str_replace('|u|', '
', $str);
	$str = str_replace('|U|', '', $str);
	$str = str_replace('|eu|', '', $str);
	$str = str_replace('|EU|', '', $str);
	$str = str_replace("\n", "
", $str);
	$str = AddLinks($str);
	return $str;
}
/*
 | DisplayContents:
 | Show a string of section body, parsing dot commands
 | currently only one command is supported
 | .C that will start or stop code section
 */
function DisplayContents($contents) {
	$incode = 0;
	$contents = SpecialCodes($contents);
  	$a = explode('
', $contents);
  	foreach($a as $val) {
		if($val[0] == '.') { /* this is a command */
	    		if($val[1] == 'C') {
				if(!$incode) {
					print "
\n";
					$incode++;
				}
				else {
	  				print "
\n";
	  				$incode--;
				}
			}
		}
		else {
      		$val = AddLinks($val);
      		print "$val
\n";
    	}
    }
  	if($incode) {
		while($incode) {
			print "
 \n";
			$incode--;
    	}
  	}
}
/*
 | DispComments:
 | Recursive function to display comments for specific article
 */
function DispComments($id, $ancestor, $level, $delprivilege) {
	global $commentstbl, $abspath, $l10n;
	global $dir, $lang;
	global $base;
	// print "dir: $dir
\n";
	$query = "SELECT * FROM $commentstbl WHERE article='$id' AND ancestor='$ancestor' ORDER BY time DESC";
//	print "Query: $query
\n";
	$result = DoQuery($query, __LINE__);
	if($result->num_rows == 0)
		return;	/* end of recursive call */
	if($level == 0)
			print "
\n";	/* spacer between two threades */
	while($line = $result->fetch_assoc()) {
		$msgnum = $line['num'];
		$title = SpecialCodes($line['title']);
		if(empty($title))
			$title = _("No title");
		$msguser = $line['name'];
		$email = $line['email'];
		$website = $line['website'];
		$comment = $line['comment'];
		$time = $line['time'];
		$i = $level * 10;
		if($dir == 'rtl')
			$style = "margin-right:${i}px";
		else
			$style = "margin-left:${i}px";
		print "
\n";
		print "
$title \n";
		if($website)
			print "
$msguser ";
		else
			print "$msguser \n";
		list($year, $month, $day, $hour, $min, $sec) = sscanf($time, "%d-%d-%d %d:%d:%d");
		$timestr = GetTimeStr($hour, $min, $sec, $month, $day, $year);
		print "$timestr\n";
		/* Put message contents as DIV that will be displayed when clicking on message */
		print "
\n";
		DisplayContents($comment);
		/* show link to add response */
		$id1 = urlencode($id);
		$url = "${base}articlemsg.php?id=$id1&ancestor=$msgnum&lang=$lang";
		$url = urlencode($url);
		print "
";
		print _("Add comment");
		print "      \n";
		
		if($delprivilege == 1) {
			$l = _("Delete comment");
			$url = "?action=delcomment&id=$id1&num=$msgnum";
			print "
$l\n";	
			print "  
$email\n";
		}
		print "
\n";
		print "
\n";
		print "
\n";
		DispComments($id, $msgnum, $level+1, $delprivilege, $dir);
	}
}
if($action == 'delcomment') {
	$num = $_GET['num'];
	
	$query = "DELETE FROM $commentstbl WHERE num='$num'";
	$result = DoQuery($query, __LINE__);
	RecursiveDelete($num);
	$url = urldecode($id);
	print "
\n";
	return;
}
$commenturl1 = urlencode($commenturl);
$url = "${base}articlemsg.php?id=$commenturl1&ancestor=0&lang=$lang";
$url = urlencode($url);
print "