[SOLVED] 代写 html shell software Assignment

30 $

File Name: 代写_html_shell_software_Assignment.zip
File Size: 348.54 KB

SKU: 1450078477 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


Assignment
Write Erlang code to model a group of sensors. Your solution will consist of three modules
One Erlang module, in source file sensor.erl, should model a sensor process.
Based on Dan Duchamps assignment 5, from prior editions of this course.
1

1 2 3 4 5 6 7 8
AnotherErlangmodule,insourcefilewatcher.erl,shouldmodelwatcher processes.
Finally in source file main.erl, you will have two functions, start0 and setuploop2. The code for start0 is given below, that for setuploop2 you have to implement together with the code in modules sensor.erl and watcher.erl.
Each watcher process should keep watch on as many as 10 sensors, then number of sensors being specified as an argument. Occasionally each sensor will report a measurement to its watcher. The measurement is a random integer in the range 110. Sensors should report measurements to their watcher every few seconds, the interval between successive measurements being a random number of milliseconds in the range 110000.
Every once in a while, a sensor will crash. When a sensor crashes, its watcher process should detect that fact and start a replacement sensor process. This should be achieved using monitors. Monitors are similar to links. Further details are provided in the next section.
Once you have your logic working, try running with a very large number of processes. If you have written your loops with proper tail recursion, it should work. For instance, the example solution runs correctly with 300,000 simultaneous sensor processes on a standard modern desktop. To run with a large number of sensors, you might have to expand Erlangs process limit. To increase the cap, start Erlang like this: erl P NUMPROC where NUMPROC is a power of two that specifies the process limit. Erlang creates many additional background processes so NUMPROC will have to be substantially larger than the number of sensors.
Here is the code for main:start0.
start
ok,N io:freadenter number of sensors , d , if N1
3.1
io:fwritesetup: range must be at least 2n,; true
Numwatchers1N div 10 ,
setuploopN, Numwatchers end.
Software Details
Sensor:
Each sensor has an integer ID: 0, 1, etc.
A measurement report should be a tuple that includes only the sensors ID number and the measurement number.
Generate a random measurement like this: Measurementrand:uniform11
2

If Measurement is in the range 111, report it to the watcher process. If Measurement is 11, crash with the report anomalousreading
Sleep for a random time between measurements like this: Sleeptimerand:uniform10000 ,
timer:sleepSleeptime
To crash, call exit1, as seen in class and described at http:erlang.orgdocmanerlang.html
Watcher:
Each sensor is watched by a single watcher process. For example, if there are 93 sensors then one watcher should watch sensors 09, a second should watch sensors 1019, and so on; the tenth watcher should watch sensors 9092.
A process P can monitor another process Q. In this case, if Q terminates, then P will be notified via a message. Here is an example,
1 106 erlang:monitorprocess, spawnfunexitoops end.
2 Ref 0.3776929009.2321809409.125448
3 107 flush.
4 Shell got DOWN,Ref0.3776929009.2321809409.125448,process,0.246.0,oops
5 ok
You can also spawn and then monitor a process in one action using spawnmonitor3. To start a new process and have the caller act as its monitor:
Pid, Ref spawnmonitorModule, Function, Argumentlist
Here, Ref is a unique reference that identifies the monitored process but Ref is different from the Pid. We do not need references in this assignment; you can throw away the returned reference like this:
Pid,spawnmonitorModule, Function, Argumentlist
Each watcher should maintain a list of its sensors. Each item on the list should be a tuple that associates a sensors ID number with its current Pid. You will have to update this list when a particular sensor is restarted because the new sensor process will have the same sensor number but a dif ferent Pid from the crashed sensor process. Read about the lists:delete function at http:erlang.orgdocmanlists.html.
Each watcher should print a line of output using io:fwrite whenever any of these events occurs:
Watcher starts: print initial list of sensors; each list item is a tuple that contains ID and Pid
3

Receives sensor reading: print sensor number and measurement num ber
Detects that sensor died: print sensor number not Pid and reason it died
Sensor is restarted: print updated list of sensors; each list item is a tuple that contains ID and Pid
4

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] 代写 html shell software Assignment
30 $