MDB puzzle

On a lighter note, I'd thought I post an "MDB puzzle" for the truly masochistic out there. I was going to post two, but the second one was just way too hard, and I was having a hard time finding a good test case in userland. You can check out how we hope to make this better over at the MDB community. Unfortunately I don't have anything cool to give away, other than my blessing as a truly elite MDB hacker. Of course, if you get this one right I might just have to post the second one I had in mind...

The rules are simple. You can only use a single line command in 'mdb -k'. You cannot use shell escapes (!). Your answer must be precise, without requiring post-processing through some other utility. Leaders of the MDB community and their relatives are ineligible, though other Sun employees are welcome to try. And now, the puzzle:

Print out the current working directory of every process with an effective user id of 0.

Should be simple, right? Well, make sure you go home and study your MDB pipelines, because you'll need some clever tricks to get this one just right...

Technorati Tags:

Comments:

(The < in "<p=K" got mistakenly eaten as HTML in the above.)
echo "::walk proc p | ::print proc_t p_cred | ::print cred_t cr_uid | ::grep .==0 | ::eval <p=K | ::print proc_t p_user.u_cdir | ::print vnode_t v_path" | mdb -k
Moral of story: be sure all who developed a technology are community leaders before holding a contest involving said technology. ;)

Posted by Bryan Cantrill on June 23, 2005 at 05:10 PM PDT #

Dammit, you ruined all my fun, and within the first hour too :-(

But you could've used a few more pointer dereferences to clean it up:

<tt>::walk proc p | ::print proc_t p_cred->cr_uid | ::grep .==0 | ::eval <=K | ::print proc_t p_user.u_cdir->v_path</tt>

Guess I will need the next puzzle (after I make you a community leader, of course).

Posted by Eric Schrock on June 23, 2005 at 05:25 PM PDT #

This is what I have after one hour. You know it's not correct :-) echo '::walk proc | ::print -d proc_t p_pidp->pid_id p_cred->cr_uid p_user.u_cd ir->v_path' | mdb -k I will need more tutorial on "::grep" and "::eval" commands. And more example for mdb in general.

Posted by sitchai on June 23, 2005 at 07:42 PM PDT #

In "eval <p=K",
"<p" is a value of variable p but what does "=K" mean?

Posted by sitchai on June 23, 2005 at 07:53 PM PDT #

HTML fscked up my previous post. Would you please explain the eval command above?

Posted by sitchai on June 23, 2005 at 07:59 PM PDT #

Okay, could be wrong on this, but I can only learn ;). <p /> First eval, to use the full defination from the mdb docs evaluates and then runs the command that you give it, so in the case of the examples the eval segment is pulling out a pointer (the K tells it to get a uintptr_t) to the proc structure that you are interested in which you then just print out the values from. <p /> As an example, if you just run the command sequence above as far as the eval you get something like
> ::walk proc p | ::print proc_t p_cred->cr_uid | ::grep .==0 | ::eval <lt;p=K
                fffffffffbc20a80
                ffffffff8111f8f8
                ffffffff81120520
                ffffffff81121148
                ffffffff84444c88
                ffffffff835074b8
Which are your pointers back to the relevant proc_t structures. <p /> Hopefully this explains it (and if I'm wrong I'm sure Eric can explain it properly).

Posted by fintanr on June 23, 2005 at 09:28 PM PDT #

Blurghh, html formating again, the dcmd sequence should have given output along the lines of
                ffffffff81119528
                ffffffff81116488
                ffffffff81114010
                ffffffff81117cd8
                ffffffff8111bc30
and the ::eval chunk should read ::eval <p=K

Posted by fintanr on June 23, 2005 at 09:30 PM PDT #

Post a Comment:
Comments are closed for this entry.
About

Musings about Fishworks, Operating Systems, and the software that runs on them.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today