A GUI for ps(1) Built with Mozilla

Give your command-line tasks a GUI with the Mozilla platform.

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:

mkdir -p $M5H/chrome/psviewer/content
cp *  $M5H/chrome/psviewer/content
vi    $M5H/chrome/psviewer/content/contents.rdf
vi    $M5H/chrome/installed-chrome.txt

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:


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



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Support material for

Anonymous's picture

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

stoneknife's picture

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

Anonymous's picture

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

BArchis's picture

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:


(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:


(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....