diff options
Diffstat (limited to 'lib/procps.lua')
-rw-r--r-- | lib/procps.lua | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/lib/procps.lua b/lib/procps.lua deleted file mode 100644 index 057f2e2..0000000 --- a/lib/procps.lua +++ /dev/null @@ -1,77 +0,0 @@ - -module(..., package.seeall) - -require("posix") - --- the following methods are available: --- /proc/<pid>/stat the comm field (2nd) field contains name but only up --- to 15 chars. does not resolve links --- --- /proc/<pid>/cmdline argv[0] contains the command. However if it is a script --- then will the interpreter show up --- --- /proc/<pid>/exe link to exe file. this will resolv links --- --- returns list of all pids for given exe name - ---[[ --- gives lots of false positives for busybox -local function is_exe(path, name) - local f = posix.readlink(path.."/exe") - if f and (f == name or posix.basename(f) == name) then - return true - else - return false - end -end -]]-- - - -local function is_stat(path, name) - local f = io.open(path.."/stat") - if (f) then - local line = f:read() - local p = string.gsub(line, ".*%(", "") - p = string.gsub(p, "%).*", "") - f:close() - end - if p ~= nil then - if string.len(name) <= 15 and p == name then - return true - end - end - return false -end - -local function is_cmdline(path, name) - local f = io.open(path.."/cmdline") - if f == nil then - return false - end - local line = f:read() - f:close() - if line == nil then - return false - end - local arg0 = string.gsub(line, string.char(0)..".*", "") - if posix.basename(arg0) == name then - return true - end -end - -function pidof(name) - local pids = {} - local i, j - - for i,j in pairs(posix.glob("/proc/[0-9]*")) do - local pid = tonumber(posix.basename(j)) - if is_stat(j, name) or is_cmdline(j, name) then - table.insert(pids, pid) - end - end - if #pids == 0 then - pids = nil - end - return pids -end - |