Eric Schrock's Blog

MDB puzzle

June 23, 2005

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:

7 Responses

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

  2. 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).

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

  4. In “eval <p=K”,
    “<p” is a value of variable p but what does “=K” mean?

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

  6. 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).

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

Recent Posts

April 21, 2013
February 28, 2013
August 14, 2012
July 28, 2012

Archives