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
|
# File 'lib/kanrisuru/core/system/parsers/lsof.rb', line 9
def parse(command)
lines = command.to_a
current_row = nil
current_pid = nil
current_user = nil
current_command = nil
rows = []
lines.each do |line|
case line
when /^p/
current_pid = parse_lsof(line, 'p').to_i
when /^c/
current_command = parse_lsof(line, 'c')
when /^u/
current_user = parse_lsof(line, 'u').to_i
when /^f/
rows << current_row if current_row
current_row = Kanrisuru::Core::System::OpenFile.new
current_row.pid = current_pid
current_row.command = current_command
current_row.uid = current_user
current_row.file_descriptor = parse_lsof(line, 'f')
when /^t/
current_row.type = parse_lsof(line, 't')
when /^D/
current_row.device = parse_lsof(line, 'D')
when /^s/
current_row.fsize = parse_lsof(line, 's').to_i
when /^i/
current_row.inode = parse_lsof(line, 'i').to_i
when /^n/
current_row.name = parse_lsof(line, 'n')
end
end
rows << current_row if current_row
rows
end
|