Re: [HACKERS] backend now show status in 'ps'

From: Massimo Dal Zotto <dz(at)cs(dot)unitn(dot)it>
To: hackers(at)postgreSQL(dot)org (PostgreSQL Hackers)
Cc: maillist(at)candle(dot)pha(dot)pa(dot)us (Bruce Momjian)
Subject: Re: [HACKERS] backend now show status in 'ps'
Date: 1998-06-08 15:17:52
Message-ID: 199806081517.RAA03067@pennac.cs.unitn.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>
> I have completed a patch that shows the backend status on the 'ps' line
> for each process:
>
> 24081 ./bin/postmaster -i -B 401 -d -o -F -S 1024
> 24089 /usr/local/postgres/./bin/postgres postgres test idle "" "" "" (postmaster)
> 24106 /usr/local/postgres/./bin/postgres postgres test SELECT "" "" "" (postmaster)
>
> As you can see, the backend shows the user, database, and status, which
> is either 'idle' or 'SELECT', 'UPDATE', 'VACUUM', etc. Those "" are
> there because I erased the other args. "(postmaster)" is there because
> that was the initial argv[0] value (we don't fork() anymore).
>
> This will be useful, even if we go with further status features. I am
> interested in any other information I should be showing. I believe
> there is almost zero performance overhead in assigning/showing these
> values, except that the strings should be valid during the entire time
> it is assigned to argv. We could almost display the row number as we
> scan through a table. Nifty feature.

I agree.

> This worked under BSDI, because if you say argv[1] = "test", and argc is
> at least 2, it shows "test" in ps. If argc is only one (they didn't use
> any args), it will not show it, but I have added a nifty hack to the
> postmaster to re-exec it so it is sure to have a least three args. I
> strip them off before processing. You can see the patch in the patches
> list.

I believe, this won't work under Linux. I'm not 100% sure about it but from
what I can remember Linux pass a copy of the original argv to the program
and changing it doesn't change the argv strings shown by ps. You must zap
the strings itself inside the page allocated for argv.
I would suggest the following code which works fine also under linux, even
with zero args.

#ifdef linux
progname = argv[0];
/* Fill the argv buffer vith 0's, once during the initialization */
for (i=0; i<argc; argc++) {
memset(argv[i], 0, strlen(argv[i]));
}
#endif

/* Build status info */
sprintf(status, "%s ...", ...);
#ifdef bsdi
argv[1] = status;
#endif
#ifdef linux
/* Print the original argv[0] + status info in the argv buffer */
sprintf(argv[0], "%s %s", progname, status);
#endif

I would also suggest using only lowercase messages if possible. They don't
hurt the eyes too much.

> BSDI uses the kvm interface for ps, which allows 'ps' to grab the args
> right out of the process's address space. This is a nifty trick,
> considering that 'ps' is run inside the address space of another
> process. I did not use the sendmail wack-the-environment method of
> changing 'ps'-displayed args, because it is ugly code, and will probably
> cause more problems than it is worth. Hopefully most platforms will
> allow this kind of assignment to be shown in 'ps'.
>
> I have also removed some unused args to pg_exec_query(). Again, it is
> in the patch posted.
>
> --
> Bruce Momjian | 830 Blythe Avenue
> maillist(at)candle(dot)pha(dot)pa(dot)us | Drexel Hill, Pennsylvania 19026
> + If your life is a hard drive, | (610) 353-9879(w)
> + Christ can be your backup. | (610) 853-3000(h)

--
Massimo Dal Zotto

+----------------------------------------------------------------------+
| Massimo Dal Zotto e-mail: dz(at)cs(dot)unitn(dot)it |
| Via Marconi, 141 phone: ++39-461-534251 |
| 38057 Pergine Valsugana (TN) www: http://www.cs.unitn.it/~dz/ |
| Italy pgp: finger dz(at)tango(dot)cs(dot)unitn(dot)it |
+----------------------------------------------------------------------+

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Doug Lo 1998-06-08 15:26:52 Re: [HACKERS] Re: [GENERAL] Should I run regression tests?
Previous Message Bruce Momjian 1998-06-08 15:16:20 Re: [HACKERS] Need some help on code