Lab 6


Since you've just had a labtest, this will be a shorter lab.

The Exercises

There is just 1 exercise.
  1. In class, you've been introduced to malloc() and related functions. And you used malloc/realloc in q3 of the last lab.

    It was emphasized that you should always check the return value of malloc, and take special steps if it is NULL - usually output a message to standard error and quit with a non-zero exit status. Generally, students learn to put in such code, but never get to see it run; i.e. they never see malloc fail. Your job here will be to make it fail.

    To make malloc fail, you must set the resource limits for the process (the shell and all of its descendants, i.e. programs you run). Now write a C program called q1.c. It should repeatedly call malloc on larger and larger arguments until it fails. Here, roughly, is how you do this: And a final note: if you try replacing calls to malloc with calls to calloc, as in
    calloc(1, currentSize);
    
    you should find that the results are the same.

    BUT this will not work if you use realloc - the resource limits set with ulimit will be ignored. Try it if you like, and use <ctrl>C to kill the running program.

    Submit your program with the following command:
    $ submit 2031 lab6 q1.c
    

end of lab 6