Question: INFO ptr[2] = Alloc(5) returned 1001 (searched 3 elements) Free List [ Size 3 ]: [ addr:1000 sz:1 ] [ addr:1006 sz:2 ] [ addr:1008
INFO
ptr[2] = Alloc(5) returned 1001 (searched 3 elements)
Free List [ Size 3 ]: [ addr:1000 sz:1 ] [ addr:1006 sz:2 ] [ addr:1008 sz:92 ]
ptr[3] = Alloc(8) returned 1008 (searched 3 elements)
Free List [ Size 3 ]: [ addr:1000 sz:1 ] [ addr:1006 sz:2 ] [ addr:1016 sz:84 ]
Free(ptr[3]) returned 0
Free List [ Size 4 ]: [ addr:1000 sz:1 ] [ addr:1006 sz:2 ] [ addr:1008 sz:8 ] [ addr:1016 sz:84 ]
PROBLEM
Write an awk script list_sizes.awk that prints the size of every element in the free list, in order, after each Free or Alloc operation. Your program should act like this:
$ awk -f list_sizes.awk malloc-out.txt | head
99
1 99
1 92
1 7 92
1 2 92
1 2 84
1 2 8 84
1 5 2 8 84
5 2 8 84
2 8 84
Hint: you can use printf and loops in awk programs. In both cases the syntax is similar to C. Here is an example of an awk program with a loop:
{ n = $1
for (i=0; i < n; i++) {
printf(%s , $(2+i))
}
}
This program assigns the value in field 1 to variable n, then prints fields 2, 3, 4 up to field 2 + n - 1.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
