0% found this document useful (0 votes)
38 views

OS Assignment - 2

This document provides instructions for an operating systems lab assignment involving 3 tasks: 1) Copying and modifying code to demonstrate process execution using execvp() system call. 2) Writing a program to perform read and write operations on a file, prompting the user to add more data. 3) Writing a program to retrieve file information and permissions, and explaining the pros and cons of soft and hard links.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

OS Assignment - 2

This document provides instructions for an operating systems lab assignment involving 3 tasks: 1) Copying and modifying code to demonstrate process execution using execvp() system call. 2) Writing a program to perform read and write operations on a file, prompting the user to add more data. 3) Writing a program to retrieve file information and permissions, and explaining the pros and cons of soft and hard links.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Operation System (LAB)

Assignment 2
INSTRUCTIONS:
You are required to complete the tasks according to the following instructions.

• At the start of each task, in every program, you are required to print PROCESS ID of the process,
your NAME, ROLL NUMBER and SECTION.
• You must attach the complete screenshots of the output.
• You must write code alongside the screenshot.
• Illustrate the code reason where necessary.

TASKS:
1. Copy the following code, Remove the errors, if any and compile it using command:
• gcc TestPogram.c -o test
TestProgram.c

#include<stdio.h>
#include<unistd.h>
int main(int argc, char *argv[])
{
printf(“\nMy Process ID is: %d\n”, getpid());
printf(“I am Called by exec Process”);
printf(“\nGOING BACK TO MAIN…?????”)
}
After executing the above code, Create a new C Program and copy the following code, Remove the errors,
if any and compile it using command:
gcc ExecProgram.c -o exec

ExecProgram.c

#include<stdio.h>
#include<unistd.h>
int main(int argc, char *argv[])
{
printf(“Process ID: %d\n”, getpid());
printf(“Main Thread..\nExecuting other program”);
char *args[] = { “./test”, ”Hello” , “From”, “Main”,
NULL};
execvp(args[0], args);
printf(“\nRETURNED TO MAIN…?????”);
}
Analyze the output of ./exec and answer the following questions:

• Do the TestProgram.c and ExecProgram.c share the same address space?


• Do the TestProgram.c and ExecProgram.c have the same process ID? If yes, then explain with
reason.
Operation System (LAB)
Assignment 2
• In ExecProgram.c, the statement “Returned to main” (after execvp system call )will never be
executed. Explain.

2. Write a program to perform read and write operations in a file.


• You are required to pass the name of the file through command line arguments. The program
will write into the file and before closing the file, you must read that data from file and display
it on the screen.
• Ask user if he wants to add more data into the file or not? If the user demands to add more data,
the program must ask user the data to be added and append it in the file. This process while be
executed iteratively until user wish to ‘exit’.
• Attach Screen shot of the output and code.

3. A symbolic or soft link is an actual link to the original file, whereas a hard link is a mirror copy of
the original file. If you delete the original file, the soft link has no value, because it points to a non-
existent file. But in the case of hard link, it is entirely opposite. Even if you delete the original file, the
hard link will still has the data of the original file. Because hard link acts as a mirror copy of the original
file. Symbolic Link and Hard links. Write Pros and Cons of Soft and Hard links. Also, write a program
that reads file name, retrieve all the information (status) about that file and then display the SIZE and
PERMISSIONS granted to the file.
• Attach the screenshot of output and code.

NOTE:
• Copy all the attached files (.docx, .c) in a folder. The name of the folder must be like
Section-Roll No. (e.g. E1-0026-BSCS-13).
• You must submit assignment till 22-06-2020 before 02:00 pm. Late submissions will be
marked as ZERO.
• Do not copy anything from others. Plagiarized content will also be marked as ZERO.

You might also like