-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProceso.pm
126 lines (70 loc) · 1.78 KB
/
Proceso.pm
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package dsys::Proceso;
use strict;
use parent qw(dsys::Info);
use dsys::ProcesoLocks;
use dsys::ProcesoStatus;
use dsys::ProcesoDescriptor;
sub tiene{
pid=>undef,
ppid=>undef,
exe=>undef,
comando=>undef,
estado=>undef,
usuario=>undef,
usuario_efectivo=>undef,
memoria_residente=>undef,
memoria_virtual => undef,
pico_memoria_residente => undef,
pico_memoria_virtual => undef,
etime => undef,
}
sub __parsear{
$_[0]->{exe} = $_[0]->__cargarExe;
$_[0]->__cargarStatus;
$_[0]->__cargarDescriptores;
$_[0]->__cargarLocks;
}
sub __cargarExe{
readlink('/proc/' . $_[0]->{pid} . '/exe');
}
sub __cargarStatus{
my $status = dsys::ProcesoStatus->new(pid=>$_[0]->{pid})->parsear;
$_[0]->{etime} = (stat("/proc/" . $_[0]->{pid}))[10];
$_[0]->agregarInfo($status);
$_[0]->{ppid} = $status->{ppid};
$_[0]->{comando} = $status->{name};
#
# uids
#
my ($ruid, $euid, $suid, $filesytem) = split(/\s/, $status->{uid});
$_[0]->{usuario} = getpwuid($ruid);
$_[0]->{usuario_efectivo} = getpwuid($euid);
#
# Empleo de memoria
#
($_[0]->{memoria_residente}) = $status->{vmrss} =~ /(\d+)/;
($_[0]->{memoria_virtual}) = $status->{vmsize} =~ /(\d+)/;
($_[0]->{pico_memoria_residente}) = $status->{vmhwm} =~ /(\d+)/;
($_[0]->{pico_memoria_virtual}) = $status->{vmpeak} =~ /(\d+)/;
}
sub __cargarDescriptores{
my $d;
my $ruta = '/proc/' . $_[0]->{pid} . '/fd/';
opendir($d, $ruta);
my @descriptores = grep { $_ =~ /^\d+$/ } readdir($d);
closedir $d;
foreach(@descriptores){
$_[0]->agregarInfo(
dsys::ProcesoDescriptor->new(descriptor=> $ruta . $_)->parsear
)
}
}
sub __cargarLocks{
$_[0]->agregarInfo(
dsys::ProcesoLocks->new(
pid=>$_[0]->{pid},
proceso=>$_[0]
)->parsear
);
}
1;