Need Explanation on Pri Standard Format Specifier for Ps - Possible Bug in Documentation

Need explanation on pri standard format specifier for ps - possible bug in documentation

You are being confused by PRI (immediate priority) vs. NICE (the assigned priority). PRI often gets a boost (i.e. lower value) when a process is being restarted after blocking on I/O, and conversely is lowered (higher value) if it uses up its scheduler-assigned time slot without blocking, at least with the standard scheduler. Many systems have alternative schedulers with different behaviors, but in all cases PRI is the actual current priority that the scheduler has assigned; this value is influenced by, but not defined by, the assigned "niceness".

Reference on Linux's priority management here: http://oreilly.com/catalog/linuxkernel/chapter/ch10.html

What it means that + in the c++ process state

It basically means that the process executes within a terminal session, occupying it, with a direct user access to it. A background process runs without direct user interactions. Mostly used when you want to continue using the terminal session but also need to run a time demanding computation.

You can change this state of your program by supplying the & sign after the launch command:

./a.out &

And then you can bring your process back by using the fg command or by the process id you will get after putting the process in the background.

How to nicely format floating numbers to string without unnecessary decimal 0's

If the idea is to print integers stored as doubles as if they are integers, and otherwise print the doubles with the minimum necessary precision:

public static String fmt(double d)
{
if(d == (long) d)
return String.format("%d",(long)d);
else
return String.format("%s",d);
}

Produces:

232
0.18
1237875192
4.58
0
1.2345

And does not rely on string manipulation.

Can you use a trailing comma in a JSON object?

Unfortunately the JSON specification does not allow a trailing comma. There are a few browsers that will allow it, but generally you need to worry about all browsers.

In general I try turn the problem around, and add the comma before the actual value, so you end up with code that looks like this:

s.append("[");
for (i = 0; i < 5; ++i) {
if (i) s.append(","); // add the comma only if this isn't the first entry
s.appendF("\"%d\"", i);
}
s.append("]");

That extra one line of code in your for loop is hardly expensive...

Another alternative I've used when output a structure to JSON from a dictionary of some form is to always append a comma after each entry (as you are doing above) and then add a dummy entry at the end that has not trailing comma (but that is just lazy ;->).

Doesn't work well with an array unfortunately.



Related Topics



Leave a reply



Submit