Spring 2025_CS604P_1 (1)
Spring 2025_CS604P_1 (1)
Please carefully read the following instructions before attempting the assignment.
You should consult the recommended books to clarify your concepts, as handouts are insufficient.
Assignment Submission:
You are supposed to submit your assignment in Doc or Docx format only.
Any other formats, such as scanned images, PDF, zip, rar, ppt, and BMP, will not be accepted.
You are required to send the Screenshot and C code of Question No. 1 in the same Word file.
Assignment No. 1 covers Labs 1 to Labs 4
OBJECTIVE
The objective of this assignment is to provide hands-on experience in the:
• UNIX/Linux standard files and kernel’s mechanism for file access
• Demonstration of file operations in Linux using system calls.
• Thread creation, synchronization and termination
NOTE
No assignment will be accepted after the due date via email in any case (whether it is due to load
shedding or internet malfunctioning, etc.). Hence, refrain from uploading assignments within the
last hour of the deadline. It is recommended that the solution file be uploaded at least two days
before its closing date.
Please consult your instructor before the deadline if you find any mistake or confusion in the
assignment (Question statement). After the deadline, no queries will be entertained in this regard.
Write a C program that creates two threads (T1 and T2) with the following functionality:
Thread T1:
1. Reads integers from a file named input.txt (create this file with 5 integers, one per line).
2. Calculates the sum of these integers.
3. Writes the sum to a new file output.txt.
4. Prints the sum to the console.
Thread T2:
1. Takes a string input from the user (e.g., "HelloOOS"). [Student needs to input their
Full Name here].
2. Replaces all vowels (a, e, i, o, u) with * (e.g., "H*ll***S").
3. Prints the modified string to the console and appends it to output.txt.
Requirements:
• Use pthread_create() and pthread_join().
• Students Should create a Folder with name as your Student ID and all the files input.txt,
output.txt, program.c and program.o should be placed in that folder. Also, input student
name as modified string input to replace the vowels. For example, input string should
be as “Shakeel” and modified string written in the output file and in program screen
shot should be “Sh*k**l”
• Zero Marks will be awarded for using incorrect Student ID and Student Name in the
Folder name and Program code.
```
Program behavior:
1. The main program creates `input.txt` with numbers 10, 20, 30, 40, 50 (if it doesn't exist)
2. Thread T1:
- Reads numbers from `input.txt`
- Calculates the sum (150)
- Writes the sum to `output.txt`
- Prints the sum to console
3. Thread T2:
- Asks for user input (e.g., "HelloOS") or Student Name
- Replaces vowels with * (e.g., "H*ll**S")
- Prints the modified string to console
- Appends the modified string to `output.txt`
The “output.txt” file will contain both the sum from T1 and the modified string from T2.
Note: If you have installed the Virtual Box, you can take the Screenshot. Go to the view
menu and click on Take Screenshot
See the following link for the installation of Virtual Box and Ubuntu (Linux) on your system.
https://vulms.vu.edu.pk/CourseResources/OpenFile.aspx?File=tutorial_for_installing_virtual
box_and_ubuntu.mp4
See the following link installing gcc and compiling and running your first program in Linux.
https://vulms.vu.edu.pk/CourseResources/OpenFile.aspx?File=How%20to%20install%20gcc
%20on%20Ubuntu%20and%20compile%20a%20C%20program.mp4