
diff -r 88bf2cb5e757 -r 9ff9cd2d677a prototyp/prototyp.sql
--- a/prototyp/prototyp.sql	Mon Sep 01 21:38:26 2014 +0200
+++ b/prototyp/prototyp.sql	Mon Sep 01 22:47:19 2014 +0200
@@ -202,8 +202,7 @@
 
 CREATE TYPE unix_sql_api_processes AS (
 	id INTEGER,
-	uid INTEGER,
-	owner VARCHAR,
+	owner INTEGER,
 	command VARCHAR,
 	arguments VARCHAR[],
 	working_dir VARCHAR
@@ -214,16 +213,34 @@
 	use strict;
 	use warnings;
 	
-	use encoding "UTF-8";
+	# aptitude install libproc-processtable-perl
+	# TODO: use Proc::ProcessTable::Process;
 	
-		return_next({
-			id => 123,
-			uid => 456,
-			owner => "nikdo",
-			command => "/bin/omg",
-			arguments => ["a", "b"],
-			working_dir => "/tmp"
-		});
+	my $dir = "/proc";
+	
+	opendir(DIR, $dir) or die $!;
+	while (readdir(DIR)) {
+		if (/\d+/) {
+			my $pid = $_;
+			my @process_dir_stat = stat("$dir/$pid") or next;
+			my $uid = $process_dir_stat[4];
+			
+			open(CMDLINE, "<$dir/$pid/cmdline");
+			binmode CMDLINE;
+			my $cmdline;
+			read(CMDLINE, $cmdline, 65536);
+			
+			my @cmdline_parts = split(0x00, $cmdline);
+			
+			return_next({
+				id => $pid,
+				owner => $uid,
+				command => readlink("$dir/$pid/exe"),
+				arguments => ["xxx"],
+				working_dir => readlink("$dir/$pid/cwd")
+			});
+		}
+	}
 	
 	return undef;
 $$ LANGUAGE plperlu;




