Starting from:

$20.99

NSYSP- Homework 10 Solved

Rules:

1. Please use C language in this homework and run your program on Ubuntu

20.04.

2. Please provide Makefile to compile your homework.

3. Do not copy the others homework definitely.

Turn in your homework:

1. Please compress your homework into zip archive.

2. Naming rules: “SP_HW10.zip”.

Infrastructure for this job:

Operation description and restrictions (0 points for non-compliance): Please submit the report together with the code for this operation, no additional paper copies are required.

Command line has a total of 4 parameters:

./program [data quantity M] [transfer rate R] [consumer quantity N] [buffer size B]

1. Both Producer and Consumer are developed by process.

2. The Producer is responsible for generating M pieces of data (for example: M=1000, the data content "This is message 0"), the data interval is R millisecond (for example: R=300 ms, you will need to use the usleep() function), and then Try to deliver data to all consumers (eg: N=200).

3. The smaller the R is, the faster the data is generated. Each data is text data with a serial number, as in the above example.

4. You must design an appropriate data transfer method, otherwise when N is very large, the consumer will not be able to receive the data in time.

5. The system can only have B buffers to temporarily store B data (for example: B=3). The B data will be

Cover to the 0th data. Therefore, the data must be received in time, otherwise it will be overwritten, as shown in the following figure and so on:

limit:

1. There are 80 chars in each Data (eg: char message[80];), and each message must contain a sequence number (eg: 0, 1, 2, 3...), so that the consumer who receives the message knows this. For the first few data.

2. The solution of Shared Memory + signal is preferred for this job (if there is a better solution, this is not limited), so that the consumer can read the data in time. Consumer is passively notified to read the data, and the message must carry the data serial number when the signal is notified (the class taught how to use sigaction() to add parameters to the signal).

3. The output format is the total amount of data received by all consumers, and the loss rate is calculated. The following example: Take the amount of data M=1000, the transmission rate R=300, N=150, and B=3 as an example, the output should be:

M=1000 R=300 ms N=150

Total messages: 150,000 (meaning 1000*150)

Sum of received messages by all consumers: X

Loss rate: 1 - (X/150000)

Description of the contents of the report:

1. Please draw a line graph when the number of data is fixed at 1000, B=3, and the number of consumers is 10, 100, and 1000 (vertical axis: loss rate; horizontal axis: transmission rate (ms)) as the following example.

2. Please draw the following example when the number of data is fixed at 1000, R=500, and the number of consumers is 10, 100, 1000 (vertical axis: loss rate; horizontal axis: buffer size 1-10).

Example line chart (please change the title, vertical axis, horizontal axis and other information according to the operation requirements):

3. Please describe the operating system, memory, CPU of the host you use

4. Do you think the biggest factor that causes data loss is Memory or CPU or buffer size? Why?

5. Design another program (given fixed (M, B, R, N), such as: (1000, 3, 500, 150)), how to effectively reduce the Loss rate?

More products