OPERATING SYSTEM LAB RECORD
UNIVERSITY
VISION
To be a Center of Excellence of International Repute in Education and Research.
MISSION
To Produce Technically Competent, Socially Committed Technocrats and Administrators through Quality Education and Research.
DEPARTMENT
VISION
To become a Centre of Excellence in Teaching and Research in the field of Computer Science and Engineering.
MISSION
To prepare the students for a prospective career in IT industry and for higher learning by imparting sound technical knowledge.
To carry out research in cutting edge technologies in computer engineering to meet the requirement of the industry and society.
CSE 284 – Operating Systems Lab
List of Programs
1. Study of basic Commands in Linux Operating System
2. Shell programming using control statements
3. Shell programming using loops, patterns, expansions and substitutions
4. Write programs using the following system calls (fork, exec, getpid, exit, wait, close, stat,
opendir, readdir).
5. Write programs using the I/O system calls (open, read, write, etc).
6. Simulation of Linux commands.
7. Implementation of CPU Scheduling Algorithms(FCFS, SJF, RR, Priorty).
8. Implementation of Page Replacement Algorithms (LRU, OPT, FIFO).
9. Implementation of memory allocation algorithms (First Fit, Best Fit, Worst Fit)
10. Implement the Producer – Consumer problem using semaphores.
11. Simulation of Shared Memory Concept.
12. Implementation of bankers Algorithm.
13. Implementation Disk Scheduling Algorithms
BASIC LINUX COMMANDS
EX. NO. 1a WORKING WITH FILES AND DIRECTORIES
AIM:
To study the UNIX commands for accessing files and directories.
COMMANDS:
cat --- for creating and displaying short files
chmod --- change permissions
cd --- change directory
cp --- for copying files
date --- display date
echo --- echo argument
ftp --- connect to a remote machine to download or upload files
grep --- search file
head --- display first part of file
ls --- see what files you have
lpr --- standard print command
more --- use to read files
mkdir --- create directory
mv --- for moving and renaming files
ncftp --- especially good for downloading files via anonymous ftp.
print --- custom print command
pwd --- find out what directory you are in
rm --- remove a file
rmdir --- remove directory
rsh --- remote shell
setenv --- set an environment variable
sort --- sort file
tail --- display last part of file
tar --- create an archive, add or extract files
telnet --- log in to another machine
wc --- count characters, words, lines
1. To create a file.
Syntax: $ cat>filename
Example: $ cat>ex1
2. To view the content of the file.
Syntax: $ cat filename
Example: $ cat ex1
3. To append some details with the existing details in the file
Syntax: $ cat>>filename
Example: $ cat>>ex1
4. To concatenate multiple files
Syntax: $ cat file1 file2 > file3
Example: $ cat computer compiler>world
5. To know the list of all files in directory
Syntax: $ ls
6. To copy the file to another file
Syntax: $ cp source destination
Example: $ cp ex1 ex2
7. To rename the file
Syntax: $ mv oldfile newfile
Example: $ mv ex1 ex3
8. To delete a file
Syntax: $ rm filename
Example: $ rm ex1
9. To delete all files
Syntax: $ rm *
10. To create a directory
Syntax: $ mkdir dirname
11. To change the name of the directory
Syntax: $ cd dirname
12. To remove the directory
Syntax: $ rmdir dirname
Example: $ rmdir flower
13. Echo
i. To display the filename starting with single letter
Syntax: $ echo?
ii. To display the filename starting with two letters
Syntax: $ echo??
iii. To display the filename starting with the letter f
Syntax: $ echo f*
iv. To display the filename ending with letter f.
Syntax: $ echo *f
14. Present Working Directory
i. To display the present working directory
Syntax: $ pwd
ii. To clear the screen
Syntax: $ tput clear
iii. To calculate the values
Syntax: $ bc
iv. Uname: To know your machine name
-n: Tells machine name in network
Syntax: $ uname –n
v. To display the version number of the OS
Syntax: $ uname –r
15. Head
i. To display first 10 lines
Syntax: $ head filename
ii. To display first 6 characters
Syntax: $ head -6c filename
iii. To display 5 lines from 2 files
Syntax: $ head -5 file1 file2
16. To display last 10 lines
Syntax: $ tail filename
Example: $ tail ex3
17. Word Count
i. To display the number of words in a file
Syntax: $ wc filename
Example: $ wc ex1
ii. To display the number of characters in a file
Syntax: $ wc –c filename
Example: $ wc –c ex1
iii. To display the number of lines
Syntax: $ wc –l filename
Example: $ wc –l ex3
18. Line Number
i. To display number of lines with numbers
Syntax: $ nl filename
Example: $ nl ex1
ii. To increment the line number by 5
Syntax: $ nl –i5 filename
Example: $ nl –i5 ex3
19. Sort
i. To reverse and sort the content of file
Syntax: $ sort –r filename
Example: $ sort –r ex1
ii. To sort the content of the file
Syntax: $ sort filename
Example: $ sort ex1
iii. To sort and remove the duplicate
Syntax: $ sort –u filename
Example: $ sort –u ex1
20. VI Editor Commands
i. To compile and run shell program
Syntax: $ sh filename
Example: $ sh odd.sh
ii. To compile a C program
Syntax: $ cc –o filename filename.c
iii. To run a C program
Syntax: $ ./filename
21. To paste the contents of file
Syntax: $ paste filename1, filename2
Example: $ paste ex1, ex2
22. To display file contents page by page
Syntax: $ more filename
Ex. No. 1b General Purpose Utility Commands
AIM:
To work with some of the general purpose utility commands in UNIX.
COMMANDS:
1. Calendar:
i. To display the calendar.
Syntax: $ cal
ii. To display the previous, current and next month.
Syntax: $ cal -3
iii. To display the current month starting from Sunday.
Syntax: $ cal –s
iv. To display the current month starting from Monday.
Syntax: $ cal –m
2. Date:
i. To display system date.
Syntax: $ date
Output: Tue Jan 20 10:54:25 IST 2009
ii. To display month only.
Syntax: $ date+%m
Output: 01
iii. To display month name and month
Syntax: $date +%h%m
Output: Jan01
iv. To display month name
Syntax: $ date+%h
Output: Jan
v. To display the time in hours
Syntax: $ date+%H
Output: 10
vi. To display the time in minutes
Syntax: $ date+%M
Output: 53
vii. To display the time in AM or PM
Syntax: $ date+%r
Output: 10: 53:24 AM
viii. To display date of month
Syntax: $ date+%d
Output: 20
3. WHO
i. To display the login details
Syntax: $ who
Output: root :0 Jan 20 10:51
cs1010 pts/0 Jan 20 10:51 (172.16.1.72)
ii. To display the login user details
Syntax: $ who am i
Output: cs1010
iii. To display my login id
Syntax: $ logname
Output: cs1010
4. MAN
i. It is used to view more details of all the commands
Syntax: $ man command_name
Example: $ man date
Sample Viva-Voce questions:
1. What is UNIX?
2. How is Unix differ from Linux
3. What is operating system?
4. What are the various components of a computer system?
5. What are the different operating systems?
6. Write a command to create a directory.
7. What command can you use to display the first 3 lines of text from a file and how does it work?
8. How do you reverse the string?
9. How can you find out what a command does?
10. Write a script that prints out date information in this order: time, day of week, day number, month, year.
11. Is there a way to erase all files in the current directory, including all its sub-directories, using only one command?
Experiments addressing COs:
The experiments mentioned above address CO1
SHELL PROGRAMMING
Ex. No. 2a Sum and Average of N Numbers
AIM:
To find the sum and average of N numbers using shell programming.
ALGORITHM:
Step 1: Initialize the variables
Set s=0, i=1
Step 2: Read the input
Get the value of n
Step 3: Calculate the sum of n numbers
Get the value of a
Set s = s + a
Step 4: Increment the value of i.
Set i = i+1
Step 5: Go to step 3 if i is less than or equal to n
Step 5: Calculate the average
Set a=s/n
Step 6: Display the sum and average
SAMPLE OUTPUT:
[meera@localhost meera]$ sh sum01.sh
sum of N Numbers
Enter the number:
5
6
3
1
2
4
sum=16
Average=3
Ex. No. 2b Largest and Smallest of Three Numbers
AIM:
To find the largest and smallest of three numbers using shell programming.
ALGORITHM:
Step 1: Read the values
Get the value of a, b, c, n
Step 2: If n is equal to 1 then check the largest of three numbers.
Step 2a: If a is greater than b and a is greater than c then print a is greater than b and c.
Step 2b: Else if b is greater than c then print b is greater than a and c.
Step 2c: Else print c is greater than a and b.
Step 3: If n is equal to 2 then check the smallest of three numbers.
Step 3a: If a is smaller than b and a is smaller than c then print a is smaller than b and c.
Step 3b: Else if b is smaller than c then print b is smaller than a and c.
Step 3c: Else print c is smaller than a and b.
SAMPLE OUTPUT:
[meera@localhost meera]$ sh largest.sh
Largest and Smallest of three numbers
Enter the three numbers
6 3 8
Choose 1. Largest and 2. Smallest
Enter the choice
1
8 is larger than 6 and 3
[meera@localhost meera]$ sh largest.sh
Largest and Smallest of three numbers
Enter the three numbers
5 4 3
Choose 1. Largest and 2. Smallest
Enter the choice
2
3 is smaller than 5 and 4
Ex. No. 2c Leap Year or Not
AIM:
To find the given year is a leap year or not using shell programming.
ALGORITHM:
Step 1: Read the input
Get the value of a
Step 2: If a%4 is equal to 0
then print a is a leap year.
Step 3: Else print a is not a leap year.
OUTPUT:
[meera@localhost meera]$ sh leap.sh
Leap Year or Not
Enter the Year
1920
1920 is a leap year
[meera@localhost meera]$ sh leap.sh
Leap Year or Not
Enter the Year
1991
1991 is not a leap year
Ex. No. 2d Odd or Even
AIM:
To find whether the given number is odd or even using shell programming.
ALGORITHM:
Step 1: Read the input.
Get the value of n.
Step 2: If the value of n%2 is equal to 0
then print the value n is a even number.
Step 3: Else print the value n is an odd number.
SAMPLE OUTPUT:
[meera@localhost meera]$ sh oddeven.sh
Odd or Even
Enter the value of n
6
6 is a even Number
Ex. No. 2e Positive or Negative
AIM:
To write a program to identify whether the given number is positive or negative using shell programming.
ALGORITHM:
Step 1: Read the input
Get the value of n
Step 2: If n is greater than 0
then print n is a positive number.
Step 3: Else if n is less than 0
then print n is a negative number.
Step 4: Else print n is equal to zero.
SAMPLE OUTPUT:
[meera@localhost meera]$ sh positivenegative.sh
Positive or negative
Enter the number
5
5 is a positive number
Ex. No. 2f Sum of digits
AIM:
To calculate the sum of digits using shell programming.
ALGORITHM:
Step 1: Initialize the variables
Set i=0, sum=0
Step 2: Read the input
Get the value of l, n
Step 3: Calculate the sum of digits
Set a=n%10
Set sum=a+sum
Set n=n/10
Set i=i+1
Step 4: Go to step 3 until i is less than l else go to step 5.
Step 5: Print sum
OUTPUT:
[meera@localhost meera]$ sh sumofdigits.sh
Sum of digits
Enter the number of digits
3
Enter the number
265
Sum of the digits: 13
Ex. No. 2g Fibonacci Series
AIM:
To write a shell program to find the Fibonacci series.
ALGORITHM:
Step 1: Read the input.
Get the value of n.
Step 2: Initialize the variables.
Set a= -1, b=1, i=0
Step 3: Calculate the series
Set c=a+b
Print c
Set a=b
Set b=c
Set i=i+1
Step 4: If i is less than n go to step 3 else go to break
OUTPUT:
[meera@localhost meera]$ sh fibonacci.sh
Fibonacci Series
Enter the value of n:
5
Fibonacci series upto 5:
0
1
1
2
3
Ex. No. 2h Factorial of a Number
AIM:
To find the factorial of the given number using shell programming.
ALGORITHM:
Step 1: Read the input
Get the value of n
Step 2: Initialize the variables
Set f=1, i=1
Step 3: If i is less than or equal to n
Set f=f*i
Set i=i+1
Step 4: Repeat the step 3 until the condition comes false.
Step 5: Print the value of f.
SAMPLE OUTPUT:
[meera@localhost meera]$ sh factorial.sh
Factorial of a number
Enter a number
5
Factorial of 5 = 120
Ex. No. 2i Student’s Mark List
AIM:
To calculate the mark list of a student using shell programming.
ALGORITHM:
Step 1: Read the input
Get the value of name, roll, a, b, c, d, e
Step 2: Calculate the sum and average
Set sum=a+b+c+d+e
Set avg=sum/5
Step 3: Print name, roll, a, b, c, d, e, sum, avg.
Step 4: If avg is less than 100 and avg is greater than 85 then
Print “Grade A”
Step 5: Else If avg is less than 85 and avg is greater than 75 then
Print “Grade B”
Step 6: Else If avg is less than 75 and avg is greater than 55 then
Print “Grade C”
Step 7: Else print “Fail”
OUTPUT:
[meera@localhost meera]$ sh marklist.sh
Student Marklist
Enter the student name
aaa
Enter the roll number
111
Enter the marks
89 78 56 84 53
Name: aaa
Roll Number: 111
Marks
Mark1: 89
Mark2: 78
Mark3: 56
Mark4: 84
Mark5: 53
Total = 360
Average= 72
Grade C
Ex. No. 2j Sum of Series
AIM:
To write a program to find the sum of series using shell programming.
S=12+22+32+…+n2
ALGORITHM:
Step 1: Read the input.
Get the value for n
Step 2: Initialize the variables.
Set i=1, s=0
Step 3: check if i is less than or equal to n
Step 4: If yes, perform the following process
Set a=i*i
Set s=s+a
Set i=i+1
Step 5: Repeat step 4 until I is less than or equal to n. Else go to step 6.
Step 6: Print sum.
OUTPUT:
[meera@localhost meera]$ sh sumofseries.sh
Sum of Series
Enter the Number:
5
Sum= 55
Ex. No. 2k Sequence of Odd Numbers
AIM:
To write a program to find the sequence of odd numbers present up to given n number.
ALGORITHM:
Step 1: Read the input.
Get the value of n.
Step 2: Initialize the variables.
Set i=1, j=1
Step 3: check if j is less than of equal to n or not.
Step 4: If yes, perform the following steps
Step 4a: If i%2 is not equal to zero, then print i
Step 4b: Increment the value of i, j.
Set i=i+1
Set j=j+1
Step 5: Repeat the step 4 until j is less than or equal to n.
OUTPUT:
[meera@localhost meera]$ sh sequenceofoddnumbers.sh
Sequence of Odd Numbers
Enter the value of n:
6
Odd number upto 6:
1
3
5
Ex. No. 2l Prime or Composite
AIM:
To write a shell program to find whether the number is prime or composite.
ALGORITHM:
Step 1: Read the input.
Get the value of n.
Step 2: If n is equal to 0 then
Print “Enter another number”
Step 3: Else if n is equal to 1 then
Print n is neither prime nor composite
Step 4: Else if n is equal to 2 then
Print n is even prime.
Step 5: Else, perform the following process.
Step 5a: Initialize the variables.
Set K=0, i=2
Step 5b: Check if i is less than n.
Step 5c: If yes, perform the following step.
i. If n%i is equal to 0 then set k=1 and break the loop.
ii. Increment the value of i.
Set i=i+1
Step 5d: Repeat the step 5c until i is less than n.
Step 5e: If k is equal to 0 then print n is prime.
Step 5f: Else print n is composite.
OUTPUT:
[meera@localhost meera]$ sh primecomposite.sh
Prime or composite
Enter the value of n:
6
6 is composite
[meera@localhost meera]$ sh primecomposite.sh
Prime or composite
Enter the value of n:
3
3 is prime
Ex. No. 2m Multiple Choice using Switch Case-Arithmetic operation
AIM:
To write a shell program to perform the arithmetic operation using switch case.
ALGORITHM:
Step 1: Initialize the variables.
Set n=1
Step 2: Check if n is less than 6
Step 3: If yes, perform the following steps
Step 4: Read the input
Get the value of m, a, b.
Step 5: Using switch case, read the choice m.
Step 5a: If the choice is 1 then perform addition
Set c=a+b
Print c
Step 5b: If the choice is 2 then perform subtraction
Set c=a-b
Print c
Step 5c: If the choice is 3 then perform multiplication
Set c=a*b
Print c
Step 5d: If the choice is 4 then perform division
Set c=a/b
Print c
Step 5e: If the choice is 5 then perform modulo
Set c=a%b
Print c
Step 6: Increment the value of n
Step 7: Repeat the process from step 4 until n is less than 6.
OUTPUT:
Enter ur choice
1----Addition
2----Subtraction
3----Multiplication
4----Division
5----Modulo
1
Enter ur number
56
23
The sum of 56 and 23 is 79
Ex. No. 2n Length of the String
AIM:
To write a shell program to find the length of the string.
ALGORITHM:
Step 1: Read the input.
Get the string for str.
Step 2: Count the length of the given string using the command wc.
Step 3: Store the result in the variable len.
Step 4: Print len.
OUTPUT:
[meera@localhost meera]$ sh lengthofstring.sh
Length of the string
Enter the string
have
length of the given string have is 5
Ex. No. 2o Pattern matching
AIM:
To write a shell program to perform various pattern search using file.
ALGORITHM:
Step 1: Initialize the variable.
Set a=0
Step 2: If a is equal to 0 then perform the following process.
Step 3: Read the input.
Get the value of choice
Step 4: If the choice is 1, create a file and search for a pattern.
Step 4a: Create and enter the content in a file using cat command.
Step 4b: Get the pattern to search.
Step 4c: Using grep command, search the pattern in the given file and store the result in a new file.
Step 4d: Print “Pattern found” and the result file and then count the no. of lines in the result file using wc command.
Step 5: If the choice is 2, search for a pattern in a particular file.
Step 5a:Read the file to be searched.
Step 5b: Get the pattern to search.
Step 5c: Using grep command, search the pattern in the given file and store the result in a new file.
Step 5d: Print “Pattern found” and the result file and then count the no. of lines in the result file using wc command.
Step 6: If the choice is 3, search for a pattern in all files.
Step 6a: Get the pattern to search.
Step 6b: Using grep command, search the pattern in all the file and store the result in a new file.
Step 6c: Print “Pattern found” and the result file and then count the no. of lines in the result file using wc command.
Step 7: If the choice is 4, set a=1 and then continue.
Step 8: Repeat from step 3 until a is equal to 0.
Ex. No. 2p Multiple Choice using Switch Case-Sum of series
AIM:
To write a shell program to perform sum of series using switch case.
ALGORITHM:
Step 1: Read the input.
Get the value for n.
Step 2: Initialize the variables.
Set q=0
Step 3: If q is less than 3, perform the following steps.
Step 4: Increment the value of q.
Set q=q+1
Step 5: If q is equal to 1, then
Step 5a: Initialize the variables
Set s=0, i=1
Step 5b: Read the input.
Get the value of n.
Step 5c: If i is less than or equal to n, then
Set s=s+i
Set i=i+1
Step 5d: Repeat the step 5c until the condition becomes false.
Step 5e: Print s.
Step 6: If q is equal to 2, then
Step 6a: Initialize the variables.
Set s=0, i=1
Step 6b: Read the input
Get the value of n
Step 6c: If i is less than or equal to n then
Set s=s+i
Set i=i+2
Step 6d: Repeat the step 6c until the condition becomes false.
Step 6e: Print s.
Step 7: If q is equal to 3, then
Step 7a: Initialize the variables.
Set s=0, i=2
Step 7b: Read the input
Get the value of n
Step 7c: If i is less than or equal to n then
Set s=s+i
Set i=i+2
Step 7d: Repeat the step 6c until the condition becomes false.
Step 7e: Print s.
Step 8: Repeat the process from Step 3 until q is less than 3.
OUTPUT:
[meera@localhost meera]$ sh sumofseries01.sh
Enter the number
6
Enter the choice
1
Sum of series --> 1+2+3+...+n
Sum of series: 21
[meera@localhost meera]$ sh sumofseries01.sh
Enter the number
6
Enter the choice
2
Sum of series --> 1+3+5+...+n
Sum of series: 9
[meera@localhost meera]$ sh sumofseries01.sh
Enter the number
6
Enter the choice
3
Sum of series --> 2+4+...+n
Sum of series: 12
[meera@localhost meera]$ sh sumofseries01.sh
Enter the number
6
Enter the choice
4
Ex. No. 2q Palindrome – Reversing a Number
AIM:
To write a shell program to find the palindrome of a given number.
ALGORITHM:
Step 1: Read the input.
Get the value of n.
Step 2: Initialize the variables.
Set i=0, a=n
Step 3: If n is greater than 0, then
Set m=n%10
Set i=i*10+m
Set n=n/10
Step 4: Repeat step 3 until the condition becomes false.
Step 5: Print i.
Step 6: If a is equal to i, then print the number is a palindrome.
Step 7: Else print the number is not a palindrome.
OUTPUT:
[meera@localhost meera]$ sh palindrome.sh
Palindrome-Reversing a Number
Enter the number
123
Reversed Number: 321
The number 123 doesnt form a palindrome
[meera@localhost meera]$ sh palindrome.sh
Palindrome-Reversing a Number
Enter the number
121
Reversed Number: 121
The number 121 form a palindrome
Ex. No. 2r Login Search
AIM:
To write a program to check whether a login is connected or not.
ALGORITHM:
Step 1: Read the input.
Get the value of n where n is the user login name.
Step 2: If the login name is present in the logined list, then print the login name is logged in.
Step 3: Else print the login name is not logged in.
OUTPUT:
[meera@localhost meera]$ sh loginsearch.sh
Enter the login number:
CS10141
No the number hasnt logged in
[meera@localhost meera]$ sh loginsearch.sh
Enter the login number:
meera
meera pts/0 Jan 27 10:13 (172.16.1.77)
Yes the number is logged in
Sample Viva-Voce questions:
1. What needs to be done before you can run a shell script from the command line prompt?
2. What is a shell?
3. How do you terminate a shell script if statement?
4. What UNIX operating system command would you use to display the shell's environment variables?
5. What code would you use in a shell script to determine if a directory exists?
6. How do you access command line arguments from within a shell script?
7. Within a UNIX shell scripting loop construct, what is the difference between the break and continue?
8. What are some ways to debug a shell script problem?
Experiments addressing COs:
The experiments mentioned above address CO1
SYSTEM CALLS
Ex. No. 3a Fork System Call
AIM:
To write a program to create a child process using the system calls –fork.
ALGORITHM:
Step 1: Include the necessary header files.
Step 2: Get the ID of the current main processor using the function getpid().
Step 3: Create a child using fork system call
Set a=fork()
Step 4: The fork() return 0 to a, if a child is created or any other value is returned.
Step 5: If a is equal to 0, then print the child ID using getpid().
Step 6: Else if a is not equal to 0, then print the child ID and the parent ID using getpid() .
Step 7: Else print error message.
OUTPUT:
[meera@localhost meera]$ cc -o fork.out fork.c
[meera@localhost meera]$ ./fork.out
Parent is 10968
HELLO FROM CHILD PROCESS
CHILD ID is 10968
Parent is 10967
HELLO FROM PARENT PROCESS 10967
HELLO FROM CHILD PROCESS 10968
Ex. No. 3b EXEC System Call
AIM:
To write a program to display time and date using exec system call.
ALGORITHM:
Step 1: Include the necessary header file.
Step 2: Using fork () system call, create child process.
Step 3: Display the id of the child process and parent process using getpid() and getppid().
Step 4: Using exec system call, display the time and date
execl(“/bin/date”, “date”, 0)
The first field is directory, 2nd field is syntax, 3rd field is set to null.
Step 5: The exec system call will terminate the child process.
OUTPUT:
[meera@localhost meera]$ cc -o exec.out exec.c
[meera@localhost meera]$ ./exec.out
Child Id is 10983
Parent Id is 10982
Tue Jan 27 11:17:10 IST 2009
End of file
Ex. No. 3c STAT System Call
AIM:
To write a program to implement STAT system call.
ALGORITHM:
Step 1: Include the necessary header file.
Step 2: Check the status of the given file.
Step 3: Store the status as integer value in the variable flag.
Step 4: If the argc is not equal to 2 then print filename is not given.
Step 5: Else if flag is equal to -1 then print file does not exist.
Step 6: Else print the file link, devices, inodes, protection, size, ownership, block size and time.
OUTPUT:
[meera@localhost meera]$ cc -o stat.out stat.c
[meera@localhost meera]$ ./stat.out exec.c
File Exists and Filename is givenThe information about the file exec.c
exec.c has 1 link
exec.c has 770 devices
exec.c has 3908662 inodes
exec.c has 33204 protection
exec.c has 0 inode devices
exec.c has 248 size
exec.c has 501 owner
exec.c has 4096 block size
exec.c has 1233035222 time
exec.c has 1233035220 time
Ex. No. 3d Wait System Call
AIM:
To write a program using wait system call.
ALGORITHM:
Step 1: Create child process using fork system call.
Step 2: Display the child id and status of the child process.
Step 3: Using exec() system call display the time and date.
Step 4: Return the child ID as the waiting ID using wait() system call.
cid=wait(&status)
Step 5: Display waiting ID and status
OUTPUT:
[meera@localhost meera]$ cc -o wait.out wait.c
[meera@localhost meera]$ ./wait.out
Parent Id is 11004
Status Id is 134513794
Tue Jan 27 11:27:27 IST 2009
Id is 11004 Status is 0
Sample Viva-Voce questions:
1. What is System call?
2. List the System call used for process management.
3. Explain fork() system call.
4. Explain exec() system call.
5. Explain stat() system call.
6. What are the differences among a system call, a library function, and a UNIX command?
7. What is pid?
8. What command is used to execute system calls from exe?
Experiments addressing COs:
The experiments mentioned above address CO1
Ex. No. 4 Input Output system Call
AIM:
To write a program to implement the concept of I/O call.
ALGORITHM:
Step 1: Include the necessary header files.
Step 2: Declare the variables needed.
Step 3: check if argc!=2 then
print “File name is not given”
Step 4: Open the file specified in the command prompt.
fd=open(argv[1],0)
Step 5: Check if fd!=-1 then write the value of n into the file.
Step 6: Else print no such file exist and perform the following process.
Step 6a: Create a new file by entering the choice Y.
Step 6b: Create the file using the built in function “ch mode+rw”
Step 6c: Concatenate the arguments and the attributes using strcat.
Step 6d: Get the value of n one by one and store the value n into the new file using write ().
OUTPUT:
[meera@localhost meera]$ cc -o iocall.out iocall.c
[meera@localhost meera]$ ./iocall.out fork.c
#include
main()
{
int a;
a=fork();
printf("\n\n\nParent is %d",getpid());
if(a==0)
{
printf("\n\tHELLO FROM CHILD PROCESS \n\t");
printf("\nCHILD ID is %d",getpid());
}
else if(a!=0)
{
printf("\n\tHELLO FROM PARENT PROCESS %d",getpid());
printf("\n\tHELLO FROM CHILD PROCESS %d\n",a);
}
else
{
printf("ERROR IN CREATION");
}
}
Sample Viva-Voce questions:
1. What is a System call?
2. What are the two different processor modes?
3. Define interrupt driven operation.
4. Define open() system call
5. Define close() system call
6. What is the use of fork() system call?
Experiments addressing COs:
The experiments mentioned above address CO1
SIMULATE UNIX COMMANDS
Ex. No. 5a Simulation of Copy Command
AIM:
To write a program for the simulation of copy command.
ALGORITHM:
Step 1: Include the necessary header files.
Step 2: Declare the variables needed.
Step 3: Check if argc ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- standard operating procedures
- introduction microsoft
- lesson 2 rome the superpower
- operating system lab record
- understanding by design unit template weebly
- house rules d20play
- section 281300 access control
- section 28 13 00 physical access control systems
- the new toyota auris
- answers to chapters 1 2 3 4 5 6 7 8 9 end of chapter
Related searches
- free operating system downloads
- operating system memory management
- memory management operating system ppt
- operating system memory management pdf
- ti 84 operating system download
- operating system structure
- operating system structure pdf
- web operating system ppt
- operating system powerpoint
- free linux operating system downloads
- operating system ppt download
- operating system ppt presentation