A GUI for ps(1) Built with Mozilla
Listing 7. Insertion of Facts into an RDF Datasource from a Script
// --- globals ---
klass.datasource
= Cc["@mozilla.org/rdf/datasource;1" +
"?name=in-memory-datasource"];
klass.rdf
= Cc["@mozilla.org/rdf/rdf-service;1"];
var schema = "http://www.example.org/ProcData#";
var props =
[ "pid", "ppid", "pcpu", "time", "vsz",
"group", "nice", "user", "args" ];
var rdf = klass.rdf.getService(Ci.nsIRDFService);
var root = rdf.GetResource(schema + "ProcList");
var child = rdf.GetResource(schema + "child");
var preds = [];
for (var p in props)
preds[p] = rdf.GetResource(schema + props[p]);
// --- mainline ---
window.addEventListener("load",load_handler,true);
// --- functions ---
function update_tree() {
var tree = document.getElementById("proc-tree");
// get the in-memory ds, not the rdf:localstore
var ds = tree.database.GetDataSources();
ds = ( ds.getNext(), ds.getNext() );
ds = ds.QueryInterface(Ci.nsIRDFDataSource);
var sub, pred, obj;
for (var i=0; i < psdata.length; i++)
{
if ( psdata[i][1] == "0" ) // a root node
sub = root;
else // a child node
sub = rdf.GetResource(
schema + "process-" + psdata[i][1]);
pred = child;
obj = rdf.GetResource(
schema + "process-" + psdata[i][0]);
ds.Assert(sub, pred, obj, true);
// add all properties for this process
sub = obj;
for (var j=0; j < psdata[i].length; j++)
{
pred = preds[j];
obj = rdf.GetLiteral(psdata[i][j]);
ds.Assert(sub, pred, obj, true);
}
}
}
function load_handler() {
var tree = document.getElementById("proc-tree");
var ds = klass.datasource.createInstance(
Ci.nsIRDFInMemoryDataSource);
tree.database.AddDataSource(ds);
update_tree();
}
Listing 7 shows the extra script logic that substitutes for a static RDF file. Adding the JavaScript data to the RDF used by the tree's template requires a process of steps. Mozilla sucks up RDF data into an object called a datasource. Because rdf:null has been specified, no datasource object exists, so one must be created and attached to the template. load_handler() does that, after the document is loaded safely. Using an onload handler is a standard HTML trick, and such tricks apply equally well to XUL. The update_tree() function then fills that datasource with RDF content for the template. It's done pretty simply. A double loop steps through each data item in the JavaScript array. For each ps(1) process, Assert() is called to create one RDF node of data (a triple of three items) that states PPID X has child PID Y and a further set of RDF nodes that states PID X has USER A or PID X has GROUP B. The <template> and the <tree> tag work together to sort those RDF nodes automatically into a tree arrangement; this is like make(1) calculating the dependency tree for all the targets stated in a given Makefile. With this script acting in place of a static RDF file, the simple process viewer is complete. Finally, the steps required to lift security by registering the code as a package are:
M5H = $MOZILLA_FIVE_HOME mkdir -p $M5H/chrome/psviewer/content cp * $M5H/chrome/psviewer/content vi $M5H/chrome/psviewer/content/contents.rdf vi $M5H/chrome/installed-chrome.txt
Listing 8. Chrome Registration Information for the psviewer Package
<?xml version="1.0"?> <RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" > <Seq about="urn:mozilla:package:root"> <li resource="urn:mozilla:package:psviewer"/> </Seq> <Description about="urn:mozilla:package:psviewer" chrome:displayName="PSViewer" chrome:author="Nigel McFarlane" chrome:name="psviewer"> </Description> </RDF>
The first vi editing session creates the file contents.rdf. It must look exactly like Listing 8. The second vi editing session adds to the file installed-chrome.txt. A single line is added:
content,install,url,resource:/chrome/psviewer/content/
When Mozilla starts up, it examines this last file. If it is modified, the directories listed are examined for contents.rdf files. Those files are then read, and like make(1), Mozilla builds in its head a picture of all the packages known to exist. All known packages have full security access, and Listing 8 adds the package psviewer. The secure files now can be displayed and run with a URL such as:
mozilla -chrome chrome://psviewer/content/tree.xul
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- New Products
- Linux Systems Administrator
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- Designing Electronics with Linux
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- Nice article, thanks for the
10 hours 35 min ago - I once had a better way I
16 hours 21 min ago - Not only you I too assumed
16 hours 38 min ago - another very interesting
18 hours 31 min ago - Reply to comment | Linux Journal
20 hours 25 min ago - Reply to comment | Linux Journal
1 day 3 hours ago - Reply to comment | Linux Journal
1 day 3 hours ago - Favorite (and easily brute-forced) pw's
1 day 5 hours ago - Have you tried Boxen? It's a
1 day 11 hours ago - seo services in india
1 day 15 hours ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




Comments
Support material for
I'm the author. I've placed a download containing some notes and minor fixes on the Web to ease the process of experimentation a bit. Get them here.
- Nigel.
Re: A GUI for ps(1) Built with Mozilla
For the most part I liked this article, particularly as I could use some of the theory behind it for a project of my own. I would like to point out, though, that neither the listings nor the text indicate directly what file names the listings might assume. Some of that can be figured out but it would have been nicer to have that available within the text.
When typed in, and also later downloaded from the archive sight, the code from the listings failed to output what is reported in the figures.. at least for the final. I'm no JavaScript programmer by any means but it appears that the initial definition of 'psdata' (listing 2) should not be 'null' but a new something, probably Array, as that has an attribute of 'push' (as used later in the code).
It would also have been nice for the second JavaScript excerpt (listing 7) to have some kind of indication that it should be inserted into the initial JavaScript (listing 2).
Ok... so I learned something in having to dig into the workings to get it working. It was a good start anyway aside from my frustration..
Re: A GUI for ps(1) Built with Mozilla
Notice also that execute_ps has a full path to the executable specified. This has to be changed as well.
After making the recommended changes in the first reply, and the above mentioned change. It crashes in a miserable fashion. No clue what the error means. It appears that certain assumptions were made in navigating the data tree, and these aren't valid across versions of Mozilla.
I really like the potential of XUL and it's got enough excitement here at work, that they're talking about rolling out Mozilla to 1000 PC's if it works as promised. It's a pity that the example in this article can't be made to work simply.
Re: A GUI for ps(1) Built with Mozilla
I've been banging my head on this for a few days, and have been able to get it to work with Mozilla built from source, as well as a binary downloaded from mozilla.org. Some thoughts:
1. The package >>must<< be registered as chrome and the .xul file invoked as 'chrome://...' or it won't work: you'll get an empty form because the JavaScript security won't be satisfied. It's probably easier to set up the registration and the .../chrome/psviewer/content directory first and then start building the code inside it.
2. When you build Mozilla from source, you get xpcshell, which allows you to invoke JavaScript files from the command line. It can help in getting the portion of code in Listing 2 working, but will not help with the combined (Listing 2 and Listing 7) JavaScript, because the operating context (i.e. we invoked the JavaScript from an .xul document) is missing.
3. Combining Listings 2 and 7 is a little more involved than simply concatenating them. You want to have all the declarations, followed by all the mainline code, followed by all the functions. (Maybe they don't absolutely have to be in order: I'm not a JavaScript jock. But it's much easier to follow what's happening.)
4. If you'd like, you can put the JavaScript inside the .xul file.
So now I've got it working, almost: if I invoke it as:
chrome://psviewer/content/psviewer.xul
(whether from the command line or in the address box)
it works (it even updates if I hit the Refresh button!), but if I invoke it as:
file://path/to/mozilla/chrome/psviewer/content/psviewer.xul
(or point File Open to the .xul file)
I get an empty form.
Why do I say 'almost'? Since I have this cool picture of the running processes on my screen, I'd really like to print it. But when I try to print it, the text disappears from the table, and when I try to do a Print Preview, Mozilla tosses its cookies with a segmentation fault.
Perhaps that's an exercise for another month....