-- vim:set ft=lua: dofile(mg.script_name:gsub('[^\\/]*$','')..'util.lua') ct=CreateContentBuilder(GZIP_THRESHOLD_BYTE) ct:Append(DOCTYPE_HTML4_STRICT..[=[
]=]..DefaultHeadContents()..[=[

# プロセス管理

]=]) post=AssertPost() if post then kill=mg.get_var(post,'kill') end for i=1,20 do ps={} killIndex=0 if PROCESS_MANAGEMENT_LIST and #PROCESS_MANAGEMENT_LIST>0 then if WIN32 then f=edcb.io.popen('powershell -NoProfile -c "gwmi win32_process -filter \\"name=\''..table.concat(PROCESS_MANAGEMENT_LIST,".exe' or name='") ..'.exe\'\\"|format-table processid,usermodetime,kernelmodetime,privatepagecount,name,commandline -hidetableheaders|out-string -width 999"') if f then for pid,ucpu,kcpu,mem,name,cmd in f:read('*a'):gmatch(' *([0-9]+) *([0-9]+) *([0-9]+) *([0-9]+) +([^\n ]+) +([^\n]*)\n') do --第0引数(通常はコマンド名)を除去 cmd=cmd:gsub(cmd:find('^"') and '^"[^"]*"? *' or '^[^ ]* *',''):gsub(' +$','') ps[#ps+1]={pid=pid,cpu=math.floor((ucpu+kcpu)/1000000)/10,mem=math.floor(mem/1024),name=name,cmd=cmd} if kill and kill:find('^'..pid..'!?$') then killIndex=#ps killForce=kill:find('!$') end end f:close() end else f=edcb.io.popen('ps -C "'..table.concat(PROCESS_MANAGEMENT_LIST,',')..'" -o pid=,%cpu=,%mem=,s=,command=') if f then for pid,cpu,mem,st,cmd in f:read('*a'):gmatch(' *([0-9]+) +([0-9.]+) +([0-9.]+) +([A-Za-z]+) +([^\n]+)\n') do ps[#ps+1]={pid=pid,cpu=cpu,mem=mem,st=st,cmd=cmd} if kill and kill:find('^'..pid..'!?$') then killIndex=#ps killForce=kill:find('!$') end end f:close() end end end if killIndex==0 then break elseif i==1 then cmd=(WIN32 and 'taskkill '..(killForce and '/f ' or '')..'/pid ' or 'kill '..(killForce and '-9 ' or ''))..ps[killIndex].pid edcb.os.execute(cmd) ct:Append('
`'..cmd..'`を実行しました
\n') end edcb.Sleep(500) end tuners=#ps>0 and edcb.GetTunerProcessStatusAll and edcb.GetTunerProcessStatusAll() or {} ct:Append([=[

PID | CPU]=]..(WIN32 and 'Time' or '')..[=[ | MEM | ]=]..(WIN32 and 'NAME' or 'ST')..[=[ | COMMAND | TUNER
--- | --- | --- | --- | --- | ---
]=]) edcb.htmlEscape=15 for i,v in ipairs(ps) do tunerStatus='' for j,w in ipairs(tuners) do if w.processID==tonumber(v.pid) then tunerStatus=('Sig:%.2f D:'):format(w.signalLv)..w.drop..' S:'..w.scramble..' sp:'..w.space..' ch:'..w.ch..(w.recFlag and ' ●' or w.epgCapFlag and ' ○' or '') break end end ct:Append('
'..v.pid..' | '..v.cpu..' | '..v.mem..' | '..(WIN32 and EdcbHtmlEscape(v.name) or v.st)..' | '..EdcbHtmlEscape(v.cmd)..' | '..EdcbHtmlEscape(tunerStatus)..'
\n') end ct:Append([=[

PID
を
する ([hang-up]の注記があるものは`]=]..(WIN32 and 'taskkill /f' or 'kill -9')..[=[`します)
]=]) ct:Finish() mg.write(ct:Pop(Response(200,'text/html','utf-8',ct.len,ct.gzip)..'\r\n'))