Skip to content

Instantly share code, notes, and snippets.

@boozook
Last active December 31, 2015 21:39
Show Gist options
  • Save boozook/8048457 to your computer and use it in GitHub Desktop.
Save boozook/8048457 to your computer and use it in GitHub Desktop.
Haxe/Neko. Missed getPID() for NekoVM. Works on mod_neko too.
package com.example;
import sys.io.Process;
/**
* Created by Alex Koz.
* Date: 20.12.13
*/
// TerribleClassNameLOL
class GetPID_example
{
private var getPID_cache;
public function getPID():{pid:Int, info:String}
{
if(getPID_cache != null)
return getPID_cache;
var p = new Process('echo', ['$$']);
var pid = p.getPid();
var ps = new Process('ps', ['-p', Std.string(pid - 1), '-o', 'pid= ,args= ']);
var res = ps.stdout.readAll().toString();
p.close();
ps.close();
var regx:EReg = ~/\s+(\d+)\s+(.*)/gi;
if(regx.match(res))
{
return (getPID_cache = {pid:Std.parseInt(regx.matched(1)), info:StringTools.trim(regx.matched(2))});
}
else
{
var result = res.split(' ');
return (getPID_cache = {pid:Std.parseInt(result.shift()), info:StringTools.trim(result.join(' '))});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment