$25
Part 1 (36 points)
In this question we will implement a C application that checks the response time of Internet URLs. The application should receive a file containing a list of URLs and the number of workers we want to use. After a successful run the application prints a numeric average of the successful URL queries, number of sites reached and the number of unknowns (for URLs it failed to test).
You will implement it in both methods, PIPE and Memory mapping. Add a flag “-f” in case you run it with pipe and without this flag the program run using memory mapping.
1. In addition to the manual pages from exercise 1, read the manual page for the following System Calls:
a. FORK(2) i.e. execute: man 2 fork
b. PIPE(2) also read PIPE(7)
c. SIGNAL(7)
d. MMAP(2)
e. semaphore.h(0p)
2. Install the libcurl development package on your VM:
sudo apt-get install libcurl3-dev
3. Create a new eclipse project for exercise 2, and change the following:
a. Project->Properties->C/C++ Build->Settings->Tool Settings->Cross GCC Linker->Libraries>Add…->”curl” (do the same with “rt” and “pthread“ instead of “curl”)
4. Complete the application ex2.c (missing parts are marked with //TODO)
Examples (numbers might vary between runs)
$ ./ex2 usage:
./ex2 NUMBER_OF_PROCESSES FILENAME
$ ./ex2 1 top10.txt
0.0146 Average response time from 8 sites, 2 Unknown
$ ./ex2 2 top10.txt -f
0.1002 Average response time from 9 sites, 1 Unknown
$ ./ex2 10 top10.txt
Illegal url detected, exiting now
Guidelines
● Use the manual.
● Make sure to always close the files you open.
○ Same goes for pipes.
● A parent must wait for all his/her child processes.
● Always check syscalls return value for errors. ALWAYS.
● You are not allowed to use any additional external libraries, if you are not sure if you are allowed to use something, ask in the forusudo m.
○ You may use any function that was already used in the provided skeleton.
● You may assume that the function input is valid.
● Feel free to change the internals of given functions, but not their signatures.
● Notice that when compiling using gcc on the terminal, you should still use the “-lcurl” flag.
● Do not change the program output, i.e. the print statements.
● The check_url function returns a URL_ERROR if a URL address doesn’t start with ‘http’. If your program receives a URL_ERROR, all processes (parent and children) must exit immediately and the following message should be printed: "Illegal url detected, exiting now".
● Hint: a struct is just a bunch of bits, you can write() and read() structs.
Using Docker for Smoke Testing
• The VM is installed with Docker software (more on that later in the semester).
• When being graded, your solution will be tested in a container identical to the one that will be built using the supplied Dockerfile.
• There are two smoke tests (sanity checks) to this exercise. You can explore the
'EX2/check_submission/do_not_change' folder for more details o The first test checks your program against 10 international URLs using memory mapping
o The second test checks your program against 8 Israeli URLs using pipe
• Usage:
o You’re given EX2 folder, containing:
▪ A ‘check_submission’ folder, which contains a python script to execute (check_submission.py).
▪ A skeleton file ‘ex2.c’
▪ Two text files: 'top10.txt', 'top128.txt' o Do not move ANY of the files inside check_submission, or you won’t be able to use our tests.
o You should edit ‘ex2.c’ with your solution.
o Each time you want to test your final submission file (zip file):
▪ Open a terminal and go the EX2/check_submission.
▪ copy your submission file (ex2-YOUR_ID.zip) to your machine (anywhere you want)
▪ Execute 'python check_submission.py <full path to your submission file>' If everything is fine, you will get:
▪ Average response times may vary. Under some conditions one or two URLs may not respond; it is fine, but make sure that at least one of your runs is without unknown sites