CCS 3105 Systems Programming Examinations
CCS 3105 Systems Programming Examinations
CCS 3105 Systems Programming Examinations
a) Write a program in C to read a text file for read only and uses perror() to display presence or
absence of an error. [5 marks]
b) Write code of a section of a program to show how memory can be reallocated using both malloc() and
realloc() [7 marks]
c) umask() always sets the process umask and, at the same time, returns a copy of the old umask.
Describe the process you will use to obtain a copy of the current process umask while
leaving it unchanged. [3 marks]
a) Explain the use of the semaphores system calls used in the code below. [7 marks]
sem_t *mutex = sem_open("/mutex", O_CREAT, 0600, 1);
for(i=0; i<5; i++) {
if(fork() == 0) {
while(sem_wait(mutex) < 0) ;
...
sem_post(mutex);
exit(0);
}
}
sem_close(mutex);
sem_unlink("/mutex");
b) Compare and contrast named and unnamed pipes [5 marks]
c) Write an algorithm for a shell script to print a given Number say 10999, in reverse order such that
the input is provided using a command Line Argument only. [3 marks]