X-Git-Url: https://git.rvb.name/weathermon.git/blobdiff_plain/c58ad4fb6f2c4c350a6aae01b100ebb4564ad8e9..24b943a6e7b7490d7cb5b9fb02b5561a8b74c697:/lib/wm_util.lua diff --git a/lib/wm_util.lua b/lib/wm_util.lua index 984f6ae..2c05bb0 100644 --- a/lib/wm_util.lua +++ b/lib/wm_util.lua @@ -1,6 +1,9 @@ #!/usr/bin/lua local socket = require "socket" +local lfs = require "lfs" +local uci = require "uci" +local posix = require "posix" function startswith(String,Start) if String then @@ -95,7 +98,6 @@ function split(s, delimiter) end function list_dir(name) - local lfs = require "lfs" local result = {} for name in lfs.dir(name) do if not startswith(name,".") then @@ -107,8 +109,6 @@ end function get_devid(config) - local uci = require "uci" - local web_devid = uci.get(config,"web","devid") if web_devid then @@ -126,4 +126,26 @@ function get_devid(config) local web_devid = io.read("*line") return web_devid:gsub(":",""):upper() -end \ No newline at end of file +end + +function get_children() + + local pid = posix.getpid() + local pidlist = list_dir('/proc') + local pids = {} + + for k,v in pairs(pidlist) do + + pcall( function () + local stats = get_file_content('/proc/'..v..'/stat') + local ppid = tonumber(split(stats,' ')[4]) + if pid == ppid then + pids[#pids+1] = tonumber(v) + end + end) + + end + + return pids + +end