0% found this document useful (0 votes)
2 views52 pages

OS Practical 1 - Merged

The document outlines a series of practical assignments for a B. Tech course in Computer Science and Engineering, focusing on Operating Systems. It includes tasks such as writing C programs, using debugging tools like GDB, managing file descriptors, and implementing CPU scheduling algorithms. Each practical exercise is designed to enhance students' programming skills and understanding of system calls and memory management.

Uploaded by

Purva Patel
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)
2 views52 pages

OS Practical 1 - Merged

The document outlines a series of practical assignments for a B. Tech course in Computer Science and Engineering, focusing on Operating Systems. It includes tasks such as writing C programs, using debugging tools like GDB, managing file descriptors, and implementing CPU scheduling algorithms. Each practical exercise is designed to enhance students' programming skills and understanding of system calls and memory management.

Uploaded by

Purva Patel
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/ 52

Institute of Computer Technology

B. Tech. Computer Science and Engineering


Sub: OS
Course Code: 2CSE402

Practical – 1

Name: Purva Patel


Enrollment No.: 23162121017
Branch: BDA
Class: 4A
Batch: 41

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

Sub: (2CSE402) OPERATING SYSTEM

PRACTICAL 2

NAME: PURVA PATEL


CLASS: 4A
ENROLLMENT NO. : 23162121017
BATCH: 41
BRANCH: BDA

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?

How GDB Debugs?


GDB allows you to run the program up to a certain point, then stop and print out the values of certain
variables at that point, or step through the program one line at a time and print out the values of each
variable after executing each line.
GDB uses a simple command line interface.

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

Sub: (2CSE402) OPERATING SYSTEM

PRACTICAL 3

NAME: PURVA PATEL


CLASS: 4A
ENROLLMENT NO. : 23162121017
BATCH: 41
BRANCH: BDA
1. Create a simple program in C that uses an array as a buffer. Perform operations
such as reading values into the buffer, modifying the buffer content, and printing
the buffer.
CODE:
OUTPUT:

2. Create a simple program in C that uses an array as a buffer. Perform operations


such as copying the string, concatenating the string and Comparing the string
using String buffer.
CODE:
OUTPUT:
Institute of Computer Technology
B. Tech Computer Science and Engineering

Sub: (2CSE402) OPERATING SYSTEM

PRACTICAL 4

NAME: PURVA PATEL


CLASS: 4A
ENROLLMENT NO. : 23162121017
BATCH: 41
BRANCH: BDA
1. Find Out how many file descriptors are being Used by your Linux system as of now?
Demonstrate step by step command and O/P. Also design program to check and report file
descriptors of all the opened files.

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

Sub: (2CSE402) OPERATING SYSTEM

PRACTICAL 5

NAME: PURVA PATEL


CLASS: 4A
ENROLLMENT NO. : 23162121017
BATCH: 41
BRANCH: BDA
1. Write a C/C++ program to understand File Copy Utility: Command-Line File Copying Tool
in C

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

Sub: (2CSE402) OPERATING SYSTEM

PRACTICAL 6

NAME: PURVA PATEL


CLASS: 4A
ENROLLMENT NO. : 23162121017
BATCH: 41
BRANCH: BDA
Demonstrate splint tool for static code analysis.

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

Sub: (2CSE402) OPERATING SYSTEM

PRACTICAL 7

NAME: PURVA PATEL


CLASS: 4A
ENROLLMENT NO. : 23162121017
BATCH: 41
BRANCH: BDA
Demonstration of process management system calls for multi-processing
using fork() and wait().

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

Sub: (2CSE402) OPERATING SYSTEM

PRACTICAL 8

NAME: PURVA PATEL


CLASS: 4A
ENROLLMENT NO. : 23162121017
BATCH: 41
BRANCH: BDA
Demonstrate CPU Scheduling Algorithm : FCFS (First Come First Serve)

Write a C/C++ Program to perform FCFS Scheduling for the following given data:

Processes : P1, P2, P3


Arrive time : 0, 1, 2
burst time : 8, 2, 4

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

Sub: (2CSE402) OPERATING SYSTEM

PRACTICAL 9

NAME: PURVA PATEL


CLASS: 4A
ENROLLMENT NO. : 23162121017
BATCH: 41
BRANCH: BDA
To Demonstrate thread management using POSIX Thread API

CODE :
OUTPUT:
Institute of Computer Technology
B. Tech Computer Science and Engineering

Sub: (2CSE402) OPERATING SYSTEM

PRACTICAL 10

NAME: PURVA PATEL


CLASS: 4A
ENROLLMENT NO. : 23162121017
BATCH: 41
BRANCH: BDA
Demonstrate IPC using shared memory concept.

1. Design a program to create a shared memory segment of


2048 bytes and write some content into it. Then create a child
process which then reads the content written by the parent
process in the shared memory segment.

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:

You might also like