0% found this document useful (0 votes)
98 views1 page

Systems Programming: Assignment #1

The document discusses 4 questions related to systems programming in C: 1. It asks about the utility of different exec functions and their invariants for overlaying the process image. 2. A code sample is given using fork() multiple times. It asks how many lines of output will be produced and child processes created. 3. It asks to write a program that produces 5 child processes and provide evidence of this using ps or top. 4. It asks to write a program using fork() and wait() such that the parent prints letters and child prints numbers without output getting jumbled.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views1 page

Systems Programming: Assignment #1

The document discusses 4 questions related to systems programming in C: 1. It asks about the utility of different exec functions and their invariants for overlaying the process image. 2. A code sample is given using fork() multiple times. It asks how many lines of output will be produced and child processes created. 3. It asks to write a program that produces 5 child processes and provide evidence of this using ps or top. 4. It asks to write a program using fork() and wait() such that the parent prints letters and child prints numbers without output getting jumbled.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Systems Programming

Assignment #1

Q1: The exec family of functions provides a facility for overlaying the process image of the
calling process with a new image. In one or two sentences, please comment on the utility of
each of the following invariants of exec functions.

int execl(const char *path, const char *arg0, ... /*, char *(0) */);
int execle (const char *path, const char *arg0, ... /*, char *(0), char *const envp[] */);
int execlp (const char *file, const char *arg0, ... /*, char *(0) */);
int execv(const char *path, char *const argv[]);
int execve (const char *path, char *const argv[], char *const envp[]);
int execvp (const char *file, char *const argv[]);

Q2. When the following program is compiled and run,

#include <iostream>
#include <sys/types.h>
#include <unistd.h>

using namespace std;

int main( ) {
fork( ); cout << "main " << endl;
fork( ); cout << "aisa " << endl;
fork( ); cout << "kio " << endl;
fork( ); cout << "ho " << endl;
return 0;
}

assuming all fork() system calls are successful, how many lines of output will be
produced? How many child processes are produced. Is it ever possible for a “aisa” to be output
before a “kio"? Why is this?

Q3: Write a program that produces five child processes. Submit evidence, via the
output of the ps or top command, that these processes are truly generated and are eventually
destroyed.

Q4: Write a C program that creates its child by fork() system call. The task of parent is to
print characters from A to Z, and the task of child is to print decimal numbers from 0 to 9. Write
this program using wait system call in such a way that results of parent and child could not be
jumble up.

You might also like