Lab-03 OS BSCS-3C
Lab-03 OS BSCS-3C
Laboratory Manual
for
Operating Systems Lab
Section BCS-4D
Semester Spring-24
./a.out 1 22
./a.out is the usual method of running an executable via the terminal. Here 1 and 22 are the
numbers we passed as command-line arguments to the program. These arguments are passed to
the primary function. In order for the main function to be able to accept the arguments, we have
to change the signature of the primary function as follows:
argc is the counter. It tells how many arguments have been passed.
arg is the character pointer to our arguments.
argc in this case will not be equal to 2, but it will be equal to 3. This is because the name ./a.out
is also passed as command line argument. At index 0 of arg, we have ./a.out; at index 1, we have
1; and at index 2, we have 22. Here 1 and 22 are in the form of character string, we have to
convert them to integers by using a function atoi. Suppose we want to add the passed numbers
and print the sum on the screen:
cout<< atoi(arg[1]) + atoi(arg[2]);
Question 1: Write a C or C++ program that accepts a file name and a substring as command
line argument and prints the no of occurrences of substring in the given file on the console.If the
file does not exist, print some error on the screen.
“Hello, this is the command line argument practice and my second day in the lab of operating
systems. I am enjoying it the alot. Hello, this is the command line argument practice and my
second day in lab of operating systems. I am enjoying it the alot.Hello, this is the command line
argument practice and my second day in the lab of operating systems. I am enjoying it the alot.”
Question 2: (MakeFile)
Create 3 files,
● header.h
● array.cpp
● main.cpp
header.h contains the declaration of the following functions
int sum(int arr[])
int avg(int arr[])
int max(int arr[])
int min(int arr[])
while array.cpp contains the definition of the above functions.
and main.cpp contains the main function to run the above code.
You are required to take the array from command line arguments.
Question 3: Write a program that uses two processes. One is called a parent and the other is
called a child. The child read the same file (mentioned above) and finds the total number of
vowels (a, e, i, o , u) in the file.
While child is processing, Parent wait for child to finish with code and prints ‘Program
completed’ message.