An example demonstrating the concepts of process forking, use of semaphores and shared memory by solving an interesting problem.
You are given an input file named Assign-2.ip. The file has n number of columns. Each column represents a separate process (not a thread). The input file is a comma separated file forming a table like following. Note that the ... here represent that there can be any number of such columns here. What you have to do is, read the input file, determine how many columns are there in the file, and then fork that many processes.
You have to write the code in a way using semaphores, that each process runs in order mentioned in the input file. Each process will print as many lines in its respective column as the size of quantum.
When user will start you program it will ask the user to enter the length of the quantum as following
[pc@user ~ ]$ Enter the length of the quantum [1-1000]:
When a user enters any value between 1 to 1000. Suppose user enters 990. It means that 990 elements in the first column will be printed on the screen and saved in the file named P-1.op. Then 990 elements from the second column will be printed on screen and saved in P-2.op , so on and so forth. Until the nth process will print its 990 elements and saves them in P-.op. Then the control goes back to the first process, and prints next 990 elements in first column. The process continues until the EOF is reached.This also means that as output there will be as many files created as the number of columns in the file. Each containing the output of each column separately. In addition there will be another output file named Assign-2.op which will contain the stdout of the program. It will save the output of the program as it happened.
Download the Code folder and using Ubuntu Bash or Windows or Linux Terminal, change current working directory to the Code folder. Then on the terminal, type
make
Then type this command:
./Assign-2.out
Hey there, I'm Haris - Maker of Things
Creator of Ultimate Facebook Scraper (one of the best software to collect Facebook data for research & analysis)
Stuck with some problem? Need help in solution development, guidance, training or capacity building? I am a Full Stack Engineer turned Project Manager with years of technical and leadership experience in a diverse range of technologies and domains. Let me know what problem you are facing at [email protected] and we can schedule a consultation meeting to help you get through it.
- Development of Web Applications, Mobile Applications, and Desktop Applications
- Development of Machine Learning/Deep Learning models, and deployment
- Web Scraping, Browser Automation, Python Scripting
If you or your company use any of my projects, like what Iβm doing or have benefited from my projects in any way then kindly consider backing my efforts.
For donations, you can follow these simple steps:
1) Free signup at TransferWise using this link: https://transferwise.com/invite/u/harism95. (Signing up through this link will save you from any transcation fee on the donation)
2) Select the amount e.g (15$) and choose the receiving/recipient's currency to be PKR. It supports multiple payment options (credit card, debit card, wire transfer etc)
3) Then it will show my info as the recipient, select it. If my name isn't shown, then type my email [email protected] in recipients.
4) Choose the reason for transfer to the one that suits you the most (in this case it could be 'General expenses') and in the reference section, you can mention 'Support'
If you face any issue in sending donation then feel free to get in touch with me at [email protected]
Thank you for your contribution!
You can get in touch with me on my LinkedIn Profile:
You can also follow my GitHub Profile to stay updated about my latest projects:
If you liked the repo then kindly support it by giving it a star β and share in your circles so more people can benefit from the effort.
If you find any bug in the code or have any improvements in mind then feel free to generate a pull request.
If you face any issue, you can create a new issue in the Issues Tab and I will be glad to help you out.
Copyright (c) 2018-present, harismuneer