Lab - II (CS) 11 September 2025
This lab contains 4 problems on
for help but must acknowledge the sources when you
submit your answers.
Submission Procedure
- Each question must contain code in separate files labelled
as
lab02-01.c, lab02-02.c , etc. - Zip the files into a single zip file named
<roll_number>.zip . - Email the zip file to
chakravarthybhagvati@uohyd.ac.in or if there is a problem with emailing zip files, share it on your Google Drive with me!
Question 1
Write a program that uses
Explain clearly in a comment at the top of your
You may use the code stub below to help!
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
/* declare some variables here */
if ((pid = fork()) != 0) {
/* Modify the variables here and print them */
} else {
/* Modify the variables and print them */
}
exit(0);
}
Question 2
Write a program that catches the signals
How will you kill this process?
You may use the code stub below
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
int main(void)
/* Set up the signal handler */
while(1) /* Puts program in infinite wait */
pause();
exit(0);
}
Question 3
Create processes
Can you make

You may use the code stub below.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
#define READ 0
#define WRITE 1
int main(void)
{
/* Declare necessary variables and create a pipe */
/* Create child processes appropriately */
/* Use a waitpid() system call in the right place */
/* Otherwise, code just hangs! */
exit(0);
}
Question 4
In this program, use the
Use the code stub below if you are stuck for inspiration!
%%file lab02-04.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
int main(void)
{
FILE *wfp, *rfp;
char line[81];
/* Set up the two pipes using popens */
/* Send information through the pipes */
/* Close the pipes and exit */
exit(0);
}