Bandwidth Consumption on a deeper level [closed] - c++

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm using an Ubuntu OS and I know one can get an average usage of bandwidth of a PC by reading the file /proc/net/dev file. However, suppose I'm transmitting files to two nodes at the same time (Total transmitting BW: 100 Mpbs). Can anyone suggest me a good idea how to get/store the information of 'Transmitting BW to Node X/Y" (X: 50 Mbps/ Y: 50 Mbps). Suggestions in C/C++ or python are highly appreciated! :)

The kernel doesn't ordinarily care beyond what the next hop for a packet is and what interface to drop it on to get it there. To make it care, you need some of linux's high-end routing capabilities. Try this:
DEV=`ip route|sed -nr 's/^default.* dev ([^ ]*).*/\1/p'`
/sbin/tc qdisc del dev $DEV root >/dev/null 2>&1
TQ="/sbin/tc qdisc add dev $DEV"
TC="/sbin/tc class add dev $DEV"
TF="/sbin/tc filter add dev $DEV"
$TQ root handle 1: htb default 0
$TC parent 1: classid 1:1 htb rate 100mbps # interesting destination 1
$TC parent 1: classid 1:2 htb rate 100mbps # ...
$TF parent 1: protocol ip u32 match ip dst 123.231.132.213 classid 1:1
$TF parent 1: protocol ip u32 match ip dst 1.2.3.4 classid 1:2
and then you can get stats with tc -s class show dev $DEV. I don't know an easier way to do this, sorry.

Have a look at the jnettop utility, either to get the information you need directly, or to find the appropriate techniques in its source code.

Related

How can i insert information to a text file in two separate columns? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I'm trying to make a little "money manager" program that keeps track of my withdrawals and deposits each month. I would like to be able to write this information to a text file where i have one column for withdrawals and another for deposits. I think this would be easy if each withdrawal was accompanied with a deposit but that is not my case.
The reason i want to have the file formatted this way is so that when i tell the program to give me a full summary i can see my withdrawals on the left and my deposits on the right. I'm starting to think that a simple textfile is not what i want to use for this program. Should i try to use an excel spreadsheet or a table in an rdms?
Rather than display the raw file itself, you should read the file data into memory and display it in a UI Grid or ListView control that give you proper columns to work with. Don't try to format the data itself (I wouldn't use a text file this either, use a binary file), format the display of the data instead.
The way I would solve this is by storing the change to the account - positive values means money into the account, negative values taking money out of the account.
If you wish to show that in two columns, then you can display the it with more spaces for withdrawals than for deposits.
There are a few options I see:
Using an rdms
Almost always it is not necessary to create elaborate file formats if you can push it into an sqlite-database.
For your application I think you would use one table with the colums (enum {deposit or withdrawal}, int amount_in_cent, timestamp).
Using a csv-file
Writing a comma-separated file with "deposit,withdrawal,date" would be trivial. With a suitable program (awk) you can even print it with nice columns.
Using a tool made for the job
gnucash exists :-)
Pretty printed format
To expand on your proposal, you could specify one maximum amount (1 million dollars?) that you would move in one transaction and then separate the columns with 11 spaces (7 for the dollars, one for the comma, two for the cents and one for a trailing space). If you viewed that file as a text file, it would show pretty much what you want.
Ex.:
2.97 Cat food
10000.00 Salary

Analytical flow-chart - decide what number must be in a specified box [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am having a lot of trouble in solving the following flowchart question.
Could you please help me as soon as possible as i have interview tomorrow?
4th question in the following link
http://placement.freshersworld.com/placement-papers/ThoughtWorks/Placement-Paper-Whole-Testpaper-18522
I cant the question as it has some structures that wont display properly here.
Please go to the link.
Thanks,
Arjun
The answer would be "3", since you want to stop the flow when the number in box 3 is the same as the number in box 8.
EDIT
If we skip to the last iteration of the loop, the steps are
Subtract: 9 - 9. Put result into box 6
Change Instruction 1. Increase box 6 by 2 (To box 8)
Is Box 8 (because we changed it in step 2) equal to box 3?
if box 8 and box 3 are the same, you end the flow.

How would I go about creating a file compressor similar to ZIP archives in a language like C/C++? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
So I was thinking of how a .zip archive is structured and then I thought, how could I create my own archive format.
You would want to know what you want to compress. E.G. zip works great for many things, but not so well for audio files. FLAC works well for audio, but poorly on text files ( provided you could find a way to apply it )
Once you had a compression scheme you would allocate the appropriate metadata so you could later decompress the information, followed by the compressed data.
Perhaps you would research A lossless compression method such as Entropy Encoding. You might decided that Arithmetic coding was more optimal than Huffman coding and decide to implement an Arithmetic codec. You might also look at Dictionary encoding if you are more interested in compressing text.
Edit in response to comment
One would have to include the entropy tables decided upon when encoding the data so it could be later decoded.
Take for example JPEG. JPEG uses a Colorspace transformation to YCrCb, Quantization, A Discrete Cosine Transformation, and then uses Huffman coding on the data. The color space transformation metadata is included in the headers. (how many bits per color and how many samples per channel, along with the size of the image. ) The quantization tables are included and an index of which table match which channel. And the used huffman tables to encode the DC and AC Coefficients. The Discrete Cosine Transformation and ZigZag Coefficient pattern is part of the standard. So after De-quantization you must IDCT the information and dezigzag the coefficients.
Basically for JPEG.
Read the given tables in the header.
Figure out the entropy encoded format with the header info about
size and color.
Use the Huffman table to expand the data segment
Dequantize appropriately
IDCT and de zigzag
You would have to make your own standard, figure out the minimum information needed to recover the information and store it in a way readable without knowing details of whats inside.
I don't know about .zip, but I would imagine it would have a couple dictionary tables and a couple entropy tables. You would de-entropy encode the datasegment (which must be somehow determined by standard or marker ), then use a reverse dictionary substitution.
Download the sources of bzip2 and compile them. And then go from there.

DataMining / Analyzing responses to Multiple Choice Questions in a survey [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have a set of training data consisting of 20 multiple choice questions (A/B/C/D) answered by a hundred respondents. The answers are purely categorical and cannot be scaled to numerical values. 50 of these respondents were selected for free product trial. The selection process is not known. What interesting knowledge can be mined from this information?
The following is a list of what I have come up with so far-
A study of percentages (Example - Percentage of people who answered B on Qs.5 and got selected for free product trial)
Conditional probabilities (Example - What is the probability that a person will get selected for free product trial given that he answered B on Qs.5)
Naive Bayesian classifier (This can be used to predict whether a person will be selected or not for a given set of values for any subset of questions).
Can you think of any other interesting analysis or data-mining activities that can be performed?
The usual suspects like correlation can be eliminated as the response is not quantifiable/scoreable.
Is my approach correct?
It is kind of reverse engineering.
For each respondent, you have 20 answers and one label, which indicates whether this respondent gets the product trial or not.
You want to know which of the 20 questions are critical to give trial or not decision. I'd suggest you first build a decision tree model on the training data. And study the tree carefully to get some insights, e.g. the low level decision nodes contain most discriminant questions.
The answers can be made numeric for analysis purposes, example:
RespondentID IsSelected Q1AnsA Q1AnsB Q1AnsC Q1AnsD Q2AnsA...
12345 1 0 0 1 0 0
Use association analysis to see if there are patterns in the answers.
Q3AnsC + Q8AnsB -> IsSelected
Use classification (such as logistic regression or a decision tree) to model how users are selected.
Use clustering. Are there distinct groups of respondents? In what ways are they different? Use the "elbow" or scree method to determine the number of clusters.
Do you have other info about the respondents, such as demographics? Pivot table would be good in that case.
Is there missing data? Are there patterns in the way that people skipped questions?

Lost update in Concurrency control? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have two transactions T and U which are executed simultaneously in a DB. How does one provide an example of the lost update problem?
We can assume that we have three accounts A,B,C and they each have £100,£200 and £300 respectively.
The "lost update" problem relates to concurrent reads and updates to data, in a system where readers do not block writers. It is not necessary for the transactions to be exactly simultaneous.
Session #1 reads Account A, gets 100.
Session #2 reads Account A, gets 100.
Session #2 updates Account A to 150 (+50) and commits.
Session #1 updates Account A to 120 (+20) and commits.
In this scenario, because Session #1 does not know that another session has already modified the account, the update by Session #2 is overwritten ("lost").
There are several ways to solve this, e.g. version numbers or before-and-after compares.
(3) Update Account A to 150 Where Account is 100 -> Account A is now 150
(4) Update Account A to 120 Where Account is 100 -> Update fail because account A is 150 and not 100
This occurs when two transactions that access the same database items have their operations interleaved in a way that makes the value of some database item incorrect.