You are on page 1of 1

The University of the West Indies

Department of Computing
COMP3101
Tutorial 3 Questions

This tutorial will require you to write C code. You can use the C code from the last lecture to assist you.

QUESTION 1

Write a C program where a parent process will create two children processes. The first child will sum
the positive whole numbers less than 20 while sleeping between each calculation. The second child
process will perform a similar operation, but will sum the positive whole numbers less than 5 and will
not sleep between each calculation. The parent process should only wait on the second process to
complete then will exit.

You should use the waitpid() system call to accomplish this. The definition of waitpid() is shown
below:

pid_t waitpid(pid_t pid, int *status, int options);

Explain your observations if any.

QUESTION 2

Write a C program where a parent process will create one child process. The parent process will then
access the virtual /proc directory, and print the resource limits associated with this process.

A description and location of the the limits file is shown below. You can use the system() system call to
use the command line to accomplish this task. Remember that the cat() function can be used to print the
contents of files.

/proc/[pid]/limits (since Linux 2.6.24)


This file displays the soft limit, hard limit, and units of
measurement for each of the process's resource limits (see
getrlimit(2)). Up to and including Linux 2.6.35, this file is
protected to allow reading only by the real UID of the
process. Since Linux 2.6.36, this file is readable by all
users on the system.

You might find the following function useful: sprintf()


eg. of usage:
char str[40];
sprintf(str,"%d is an even number", 6);

*** THE END ***

You might also like