Lab 7 is a graded exercise. You have two weeks to complete. Submit your solution to the IVLE workbin before Sunday, 30 October 2011, 10:00pm.
34 thoughts on “Lab 7”
Professor, I encountered some problems for the lab:
1. I got permission denied for the /proc//maps command
2. The stack.c runs perfectly after being compiled and doesn’t give expected output on gdb (in addition, the program exits after pressing n 3 times)
Thank you
Are you doing the lab on Sunfire? If yes, you should try it in OS lab.
Hi Ivan and Prof,
I was doing the lab7 in OS lab. I got the permission denied problem as well. How to go around it?
Moreover, although the computer is connected to “Normal Port”, it is unable to launch firefox and worst, cant even wget the lab07-A000000X.txt (any files due to some unresolve host error).
thank you.
I have this experience as well although I have typed ./stack
is there a way to check whether the bin path is configured correctly?
Johannes,
Can you please elaborate on the problem you encountered?
Professor,
For 2(a), should we make “top” sort the processes in some other order instead (say, according to the VIRT column)? Otherwise the lab07-malloc process rarely appears in the list.
Try this command.
top -p $(pgrep malloc)
or top -u | grep malloc
Jonathan, you may try my method. I made my malloc.c program print the pid and issued top -pPID. That way, top only show that particular process’ information.
By the way, the top man page used some terms that is not explained in lecture. I spent some time searching the net for it. I guess I shall just post my findings here for anyone who is also wondering what they mean.
Swapping – This term is used interchangeably as paging. Contrary to our lecture, it does not mean writting entire process core image to the memory. In most OS nowadays such true swapping rarely occurs.
swapped out – Occurs when the page is written to the disk.
swapped in – Occurs when the page is returned to the memory.
hope it helped.
Thanks for sharing.
Yes, although in the textbook we differentiate between swapping and paging, modern systems use the term interchangeably. I will however, stick to the term swapping as meaning loading the whole process into contiguous region in memory, and paging as meaning dividing virtual/physical memory into pages/frames and loading pages on demand into frames, to be more precise and to differentiate these two very different schemes.
For question 4, it says it’s worth 5 points, but it’s also worth 0 marks. Also, on the template for the answer sheet, it doesn’t provide a space for question 4. So does that mean we don’t actually have to answer that question? I’m confused.
Sorry. It’s a typo — should be 0 mark for Q4.
Why is that in lab07_malloc.c, there is an i*4 at the printf line? Why multiply by 4? Did I miss out something?
From what I understand the program is doing, for every iteration in the while loop, 1 MB of memory is malloc’ed. So shouldn’t i*4 be just i instead?
Alamak. Another typo.
I will alert the TA that if your answer is 4 times the correct one, it will be marked as correct.
For some reason, I couldn’t get the code in question 3 running. When I’m trying to compile, it gives me the following error:
/tmp/ccPOviYC.o: In function `main’:
lab07-time1.c:(.text+0x13d): undefined reference to `clock_gettime’
lab07-time1.c:(.text+0x179): undefined reference to `clock_gettime’
collect2: ld returned 1 exit status
So I found the header associated with clock_gettime (which is time.h) and included it in my code. Now I try to compile again and get the following:
/usr/include/time.h:120:8: error: redefinition of ‘struct timespec’
/usr/include/linux/time.h:9:8: note: originally defined here
/usr/include/time.h:161:8: error: redefinition of ‘struct itimerspec’
/usr/include/linux/time.h:42:8: note: originally defined here
Am I doing something wrong?
Just like in Lab 3, you need to link with the real-time library.
Try adding “-lrt” as an argument to gcc.
Professor, for questions 2(a) and 2(d), do you mean that we should be pay attention to the %MEM column instead of the %CPU column?
Jonathan,
Whatever relevant and significant difference(s) you can observe in the output.
regards,
WT
This is kinda unrelated. (i think!) but I guess I just wanna ask out of curiosity.
Some people on online forums claim that to get the first parameter of the current function, we do ebp-4. Is that true? It seems that it doesn’t apply to my intel machine.
is this related to how the stack grows? either upwards or downwards?
For question 3(b), i will like to ask if we are supposed to write down the average time taken to modify the content of a memory location, or the total time taken for N (N * average time)?
Thank you.
I am having the exact same problem despite trying on 5 terminals.
Warmest Regards,
Jon
specifically im refering to the problem where the OS lab cannot allow firefox use, wget or maps for process
The TAs reported that there are many issues with the lab machines today — possibly due to school-wide network failure.
Am checking with the lab technician.
Hi all,
Do take note that the lab07-time*.c program prints the time in MICROseconds. Whereas for question 3b, the example uses MILLIseconds. Don’t get tricked. ;)
Oooops. I cannot download the pdf file for lap 7 from any computer. Please help.
Dear Prof.,
The lab07-stack.c is now giving a 404 error…please re-upload..
Thanking you,
Vaarnan
Same. Cannot find the file on the server. Please help.
Does the maximal character includes the white space?
yes, as counted with wc.
Hello,
For some reasons I can’t download stack.c
It seems not be located on the server.
solved
Comments are closed.
Viewing Message: 1 of 1. Warning
Blog.nus accounts will move to SSO login, tentatively before the start of AY24/25 Sem 2. Once implemented, only current NUS staff and students will be able to log in to Blog.nus. Public blogs remain readable to non-logged in users. (More information.)
Professor, I encountered some problems for the lab:
1. I got permission denied for the /proc//maps command
2. The stack.c runs perfectly after being compiled and doesn’t give expected output on gdb (in addition, the program exits after pressing n 3 times)
Thank you
Are you doing the lab on Sunfire? If yes, you should try it in OS lab.
Hi Ivan and Prof,
I was doing the lab7 in OS lab. I got the permission denied problem as well. How to go around it?
Moreover, although the computer is connected to “Normal Port”, it is unable to launch firefox and worst, cant even wget the lab07-A000000X.txt (any files due to some unresolve host error).
thank you.
I have this experience as well although I have typed ./stack
is there a way to check whether the bin path is configured correctly?
Johannes,
Can you please elaborate on the problem you encountered?
Professor,
For 2(a), should we make “top” sort the processes in some other order instead (say, according to the VIRT column)? Otherwise the lab07-malloc process rarely appears in the list.
Try this command.
top -p $(pgrep malloc)
or top -u | grep malloc
Jonathan, you may try my method. I made my malloc.c program print the pid and issued top -pPID. That way, top only show that particular process’ information.
By the way, the top man page used some terms that is not explained in lecture. I spent some time searching the net for it. I guess I shall just post my findings here for anyone who is also wondering what they mean.
Swapping – This term is used interchangeably as paging. Contrary to our lecture, it does not mean writting entire process core image to the memory. In most OS nowadays such true swapping rarely occurs.
swapped out – Occurs when the page is written to the disk.
swapped in – Occurs when the page is returned to the memory.
hope it helped.
Thanks for sharing.
Yes, although in the textbook we differentiate between swapping and paging, modern systems use the term interchangeably. I will however, stick to the term swapping as meaning loading the whole process into contiguous region in memory, and paging as meaning dividing virtual/physical memory into pages/frames and loading pages on demand into frames, to be more precise and to differentiate these two very different schemes.
For question 4, it says it’s worth 5 points, but it’s also worth 0 marks. Also, on the template for the answer sheet, it doesn’t provide a space for question 4. So does that mean we don’t actually have to answer that question? I’m confused.
Sorry. It’s a typo — should be 0 mark for Q4.
Why is that in lab07_malloc.c, there is an i*4 at the printf line? Why multiply by 4? Did I miss out something?
From what I understand the program is doing, for every iteration in the while loop, 1 MB of memory is malloc’ed. So shouldn’t i*4 be just i instead?
Alamak. Another typo.
I will alert the TA that if your answer is 4 times the correct one, it will be marked as correct.
For some reason, I couldn’t get the code in question 3 running. When I’m trying to compile, it gives me the following error:
/tmp/ccPOviYC.o: In function `main’:
lab07-time1.c:(.text+0x13d): undefined reference to `clock_gettime’
lab07-time1.c:(.text+0x179): undefined reference to `clock_gettime’
collect2: ld returned 1 exit status
So I found the header associated with clock_gettime (which is time.h) and included it in my code. Now I try to compile again and get the following:
/usr/include/time.h:120:8: error: redefinition of ‘struct timespec’
/usr/include/linux/time.h:9:8: note: originally defined here
/usr/include/time.h:161:8: error: redefinition of ‘struct itimerspec’
/usr/include/linux/time.h:42:8: note: originally defined here
Am I doing something wrong?
Just like in Lab 3, you need to link with the real-time library.
Try adding “-lrt” as an argument to gcc.
Professor, for questions 2(a) and 2(d), do you mean that we should be pay attention to the %MEM column instead of the %CPU column?
Jonathan,
Whatever relevant and significant difference(s) you can observe in the output.
regards,
WT
This is kinda unrelated. (i think!) but I guess I just wanna ask out of curiosity.
Some people on online forums claim that to get the first parameter of the current function, we do ebp-4. Is that true? It seems that it doesn’t apply to my intel machine.
is this related to how the stack grows? either upwards or downwards?
hello, there’s a diagram here http://unixwiz.net/techtips/win32-callconv-asm.html (somewhere near the bottom of the page) that explained how the stack would look like…
ebp-4 points to the first local variable instead of the first parameter… i tried it on my VM: http://img440.imageshack.us/img440/1763/ebpp.jpg
hmm. does the stack always grow downwards and the heap upwards? i get the impression stack is always growing downwards…
It actually depends on the calling convention used. In the case of the C calling convention on x86, you can refer to this: http://www.cs.umbc.edu/~chang/cs313.s02/stack.shtml
There are many different calling conventions, even on x86 itself; see: http://en.wikipedia.org/wiki/Calling_convention
wow…thanks. those are great resources!
For question 3(b), i will like to ask if we are supposed to write down the average time taken to modify the content of a memory location, or the total time taken for N (N * average time)?
Thank you.
I am having the exact same problem despite trying on 5 terminals.
Warmest Regards,
Jon
specifically im refering to the problem where the OS lab cannot allow firefox use, wget or maps for process
The TAs reported that there are many issues with the lab machines today — possibly due to school-wide network failure.
Am checking with the lab technician.
Hi all,
Do take note that the lab07-time*.c program prints the time in MICROseconds. Whereas for question 3b, the example uses MILLIseconds. Don’t get tricked. ;)
Oooops. I cannot download the pdf file for lap 7 from any computer. Please help.
Dear Prof.,
The lab07-stack.c is now giving a 404 error…please re-upload..
Thanking you,
Vaarnan
Same. Cannot find the file on the server. Please help.
Does the maximal character includes the white space?
yes, as counted with wc.
Hello,
For some reasons I can’t download stack.c
It seems not be located on the server.
solved