libs/sys: fix luci.sys.processes.list() for entries with spaces i nthe STAT column (#528)
This commit is contained in:
parent
acd7248436
commit
a52a6a4f22
1 changed files with 16 additions and 25 deletions
|
@ -695,38 +695,29 @@ end
|
||||||
function process.list()
|
function process.list()
|
||||||
local data = {}
|
local data = {}
|
||||||
local k
|
local k
|
||||||
local ps = luci.util.execi("top -bn1")
|
local ps = luci.util.execi("/bin/busybox top -bn1")
|
||||||
|
|
||||||
if not ps then
|
if not ps then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
while true do
|
|
||||||
local line = ps()
|
|
||||||
if not line then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
k = luci.util.split(luci.util.trim(line), "%s+", nil, true)
|
|
||||||
if k[6] == "%VSZ" then
|
|
||||||
k[6] = "%MEM"
|
|
||||||
end
|
|
||||||
if k[1] == "PID" then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
for line in ps do
|
for line in ps do
|
||||||
local row = {}
|
local pid, ppid, user, stat, vsz, mem, cpu, cmd = line:match(
|
||||||
|
"^ *(%d+) +(%d+) +(%S.-%S) +([RSDZTW][W ][<N ]) +(%d+) +(%d+%%) +(%d+%%) +(.+)"
|
||||||
|
)
|
||||||
|
|
||||||
line = luci.util.trim(line)
|
local idx = tonumber(pid)
|
||||||
for i, value in ipairs(luci.util.split(line, "%s+", #k-1, true)) do
|
if idx then
|
||||||
row[k[i]] = value
|
data[idx] = {
|
||||||
end
|
['PID'] = pid,
|
||||||
|
['PPID'] = ppid,
|
||||||
local pid = tonumber(row[k[1]])
|
['USER'] = user,
|
||||||
if pid then
|
['STAT'] = stat,
|
||||||
data[pid] = row
|
['VSZ'] = vsz,
|
||||||
|
['%MEM'] = mem,
|
||||||
|
['%CPU'] = cpu,
|
||||||
|
['COMMAND'] = cmd
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue