-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetCommandPIDs.lua
More file actions
54 lines (41 loc) · 1.15 KB
/
Copy pathgetCommandPIDs.lua
File metadata and controls
54 lines (41 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
getCommandPIDs = function(cmd)
if not cmd then
cmd = 'torch-qlua'
end
--return sys.execute('ps -C 'torch-qlua');
local allPIDs = {}
s = sys.execute('ps -C ' .. cmd)
s2 = s
-- remove leading spaces before each line
while true do
s2 = s:gsub('\n ', '\n')
if s == s2 then
break
end
s = s2
end
while true do
idx_newline = string.find(s, '\n')
if not idx_newline then
break;
end
s2 = string.sub(s, idx_newline+1, #s)
idx_number = string.find(s2, '%d')
idx_space = string.find(s2, ' ')
if not idx_space then
break;
end
local pid = tonumber( string.sub(s2, 1, idx_space) )
table.insert(allPIDs, pid)
s = s2
end
return allPIDs
end
--[[
idx_newline = string.find(s, '\n')
s2 = string.sub(s, idx_newline+1, #s)
idx_space = string.find(s2, ' ')
local pid = tonumber( string.sub(s2, 1, idx_space) )
table.insert(allPIDs, pid)
s = s2
--]]