OS Practical 1 - Merged
OS Practical 1 - Merged
Practical – 1
Problem Definition 1: Write a simple “Hello World” program. Move the part that
outputs the text (i.e., the printf() function call), into a separate file hello.c. Edit an
appropriate interface file hello.h in order to use the subroutine in the main.c program.
Write a Makefile that maintains the program structure. Use a variable CC in the makefile
to define the compiler
Code:
main.c
add.c
hello.c
header.h
Makefile:
Output:
Problem Definition 2: Place the header files and C/C++ files in separate directory and
compile and execute those files using Makefile Utility.
Move the header.h file to the tmp directory and edit the Makefile as described below.
Code:
Makefile:
Output:
Institute of Computer Technology
B. Tech Computer Science and Engineering
PRACTICAL 2
Background:
A debugger is a program that runs other programs, allowing the user to exercise control over these
programs, and to examine variables when problems arise.
GNU Debugger, which is also called gdb, is the most popular debugger for UNIX systems to debug C
and C++ programs.
GNU Debugger helps you in getting information about the following:
● If a core dump happened, then what statement or expression did the program crash on?
● If an error occurs while executing a function, what line of the program contains the call to
that function, and what are the parameters?
● What are the values of program variables at a particular point during execution of the
program?
● What is the result of a particular expression in a program?
Points to Note
● Even though GDB can help you in finding out memory leakage related bugs, but it is not a tool
to detect memory leakages.
● GDB cannot be used for programs that compile with errors and it does not help in fixing
those errors.
Demo Tasks :
Debug program is giving a count of number which divides a given number in given range. Ex. if
passed parameter to function checkDivisible is 100(num), 1(startRange) and 14(endRange). then it
will return count = 5 because 100 is divisible by 1,2,4,5 and 10 in range 1 to 14. Demonstarte break
points , variable printing, layout , stack trace etc for the given code.
1. Debugging segmentation fault scenarios - using gdb utility for c programs.
https://courses.cs.washington.edu/courses/cse303/04au/Homework/gdb/
Tasks to be done:
Students are required to debug various code samples given in sheet attached herewith - GDB
unsolved codes.
CODE:
code1.cpp:
Corrected code:
c1.cpp:
code2.cpp:
Corrected code:
c2.cpp:
Code3.cpp:
Corrected code:
c3.cpp:
Code4.cpp:
Corrected code:
c4.cpp:
OUTPUT:
OUTPUT FOR CORRECTED CODES :
Institute of Computer Technology
B. Tech Computer Science and Engineering
PRACTICAL 3
PRACTICAL 4
OUTPUT:
2. For your online order of any item from amazon, look at the invoice generated by
Amazon. Store purchase order details like order_id, order_date, item_name, item_price,
delivery_date in system using file handling system call in a file and print all details related
to invoice.
CODE:
OUTPUT:
3. Implement program that can open the file "ICTGUNI.txt" in the current directory, and
prints out the return value of the open() system call. If " ICTGUNI.txt " exists, open() will
return a non-negative integer (three). If " ICTGUNI.txt " does not exist, then it will return
-1.
CODE:
OUTPUT:
Institute of Computer Technology
B. Tech Computer Science and Engineering
PRACTICAL 5
CODE:
OUTPUT:
2. Write a C/C++ program to understand the lseek() system call
CODE:
OUTPUT:
Institute of Computer Technology
B. Tech Computer Science and Engineering
PRACTICAL 6
CODE - 1 : lint1.c
#include <stdio.h>
int main() {
int x=10;
if(x=10) {
printf(“X is 10\n”);
} else {
printf(“X is 11\n”);
}
return 0;
}
OUTPUT:
CODE - 2 : lint2.c
#include <stdio.h>
int main() {
int x;
printf(“X=%d\n”,x);
return 0;
}
OUTPUT:
CODE - 3 : lint3.c
#include <stdio.h>
int main() {
int n;
printf(“Enter a number:”);
scanf(“%d”,&n);
switch(n)
{
case 1:
printf(“result = one\n”);
break;
case 2:
printf(“result = two\n”);
case 3:
printf(“result = three\n”);
break;
default:
printf(“Invalid”);
break;
}
}
OUTPUT:
Corrected codes and output:
lint1.c:
lint2.c:
lint3.c:
Institute of Computer Technology
B. Tech Computer Science and Engineering
PRACTICAL 7
1. Write a C/C++ program to create child processes using fork() system call and print parent
process id and child process id.
CODE :
2. Write a C/C++ program to understand the concept of fork() and wait() system call, Where
parent process will wait for child process termination and parents process gets terminate
after child process termination with exit status.
CODE :
OUTPUT:
Institute of Computer Technology
B. Tech Computer Science and Engineering
PRACTICAL 8
Write a C/C++ Program to perform FCFS Scheduling for the following given data:
Calculate Completion/Finish time, Turn Around Time and Waiting time of each processes.
CODE :
OUTPUT:
Institute of Computer Technology
B. Tech Computer Science and Engineering
PRACTICAL 9
CODE :
OUTPUT:
Institute of Computer Technology
B. Tech Computer Science and Engineering
PRACTICAL 10
CODE :
OUTPUT:
2. Using shared Memory Concept, design the below given
scenario: Input: Integer array of 10 Nos: 1,2,3,4,5,6,7,8,9,10
Operation : Addition of all ODD no by Parent Process & Addition
of all EVEN no by Child Processes.
Output:
Child Sum : 30
Parent Sum : 25
Final Sum is : 55
CODE:
OUTPUT: