Вы находитесь на странице: 1из 4

Information Security lab Assignment 3

Prafulla saxena(2016pis5249)
MNIT
23/09/2016

Problem 1

Observing the OS through the /proc le system

1.1

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

Code

# include < stdio .h >


# include < stdlib .h >
# include < string .h >
# include < unistd .h >
# include < time .h >
# define MAX_LENGTH 1024
int main ( int argc , char * argv []) {
char line [ MAX_LENGTH ];
int arg1 , arg2 ;
if ( argc >2) {
arg1 = atoi ( argv [1]) ;
arg2 = atoi ( argv [2]) ;
}
else {
// system ( " more / proc / cpuinfo | grep processor " ) ;
printf ( " first version output \ n " ) ;
system ( " more / proc / cpuinfo | grep cpu cores | uniq " ) ;
system ( " more / proc / cpuinfo | grep vendor | uniq " ) ;
system ( " more / proc / cpuinfo | grep model name | uniq " ) ;
system ( " more / proc / version | sed -n 1 p | awk { print $1 , $2 , $3 , $4 } ");
printf ( " Memory info \ n " ) ;
system ( " more / proc / meminfo | grep Mem " ) ;
printf ( " system uptime ( in sec ) \ n " ) ;
system ( " more / proc / uptime | awk { print $1 } " ) ;
printf ( " Idle time ( all cores in sec ) \ n " ) ;
system ( " more / proc / uptime | awk { print $2 } " ) ;
printf ( " system was last booted \ n " ) ;
system ( " last | head -2 | grep reboot " ) ;
}
// exit (0) ;
if ( argc >2) {

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

printf ( " \ nsecond version output \ n " ) ;


int inp1 ;
int i =1;
int pid = getpid () ;
int loop =( arg2 / arg1 ) ;
while (i <= loop ) {
printf ( " \n - - - - - - - - - - - - - - - - - - -% d time - - - - - - - - - - - - - - - - - -\ n " ,i ) ;
// printf ( " \ n " ) ;
printf ( " - - - -1 - - - - -\ n " ) ;
system ( " more / proc / meminfo | grep MemFree " ) ;
printf ( " - - - -2 - - - - -\ n " ) ;
printf ( " Percentage (%) of time Cpu spent in \ n " ) ;
system ( " top -b -n 2 | grep % Cpu | tail -1 > data . c " ) ;
printf ( " user :\ n " ) ;
system ( " cat data . c | awk { print $2 } " ) ;
printf ( " System :\ n " ) ;
system ( " cat data . c | awk { print $4 } " ) ;
printf ( " Idle :\ n " ) ;
system ( " cat data . c | awk { print $8 } " ) ;
printf ( " - - - -3 - - - - -\ n " ) ;
printf ( " Rate context Switches in System for rcu_sched process \ n " ) ;
system ( " more / proc /7/ status | grep ctxt " ) ;
printf ( " \n - - - -4 - - - - -\ n " ) ;
printf ( " Rate of disk read write in system \ n " ) ;
system ( " dd if =/ dev / zero of =/ tmp / output . img bs =64 count =1 k " ) ;
system ( " rm / tmp / output . img " ) ;
i = i +1;
}
}
return 0;
}

1.2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

Result/Observation

./ proc_parse
first version output
cpu cores
: 2
vendor_id
: GenuineIntel
model name : Intel ( R ) Core ( TM ) i3 -4005 U CPU @ 1.70 GHz
Linux version 4.4.0 -38 - generic ( buildd@lgw01 -58)
Memory info
MemTotal :
3981092 kB
MemFree :
393768 kB
MemAvailable :
466860 kB
system uptime ( in sec )
36034.52
Idle time ( all cores in sec )
138021.48
system was last booted
reboot
system boot 4.4.0 -38 - generic Sat Sep 24 09:24

still running

1.3

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

Result/Observation

./ proc_parse 2 60
second version output
- - - - - - - - - - - - - - - - - - -1 time - - - - - - - - - - - - - - - - - - - - -1 - - - - MemFree :
374656 kB
- - - -2 - - - - Percentage (%) of time Cpu spent in
user :
2.2
System :
0.6
Idle :
97.2
- - - -3 - - - - Rate context Switches in System for rcu_sched process
voluntary_ctxt_switches :
526272
n o n v o l u n t a r y _ c t x t _ s w i t c h e s : 16
- - - -4 - - - - Rate of disk read write in system
1024+0 records in
1024+0 records out
65536 bytes (66 kB , 64 KiB ) copied , 0.00183208 s , 35.8 MB / s
- - - - - - - - - - - - - - - - - - -2 time - - - - - - - - - - - - - - - - - - - - -1 - - - - MemFree :
373532 kB
- - - -2 - - - - Percentage (%) of time Cpu spent in
user :
3.0
System :
1.2
Idle :
95.4
- - - -3 - - - - Rate context Switches in System for rcu_sched process
voluntary_ctxt_switches :
526335
n o n v o l u n t a r y _ c t x t _ s w i t c h e s : 16
- - - -4 - - - - Rate of disk read write in system
1024+0 records in
1024+0 records out
65536 bytes (66 kB , 64 KiB ) copied , 0.00265066 s , 24.7 MB / s
.
.
.
.
.

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

.
.
.
.
.
.
.
- - - - - - - - - - - - - - - - - - -30 time - - - - - - - - - - - - - - - - - - - - -1 - - - - MemFree :
359428 kB
- - - -2 - - - - Percentage (%) of time Cpu spent in
user :
2.3
System :
0.4
Idle :
97.1
- - - -3 - - - - Rate context Switches in System for rcu_sched process
voluntary_ctxt_switches :
528170
n o n v o l u n t a r y _ c t x t _ s w i t c h e s : 16
- - - -4 - - - - Rate of disk read write in system
1024+0 records in
1024+0 records out
65536 bytes (66 kB , 64 KiB ) copied , 0.00273916 s , 23.9 MB / s

Вам также может понравиться