finding process id of a window
Jochen.Baier at stud.uni-karlsruhe.de
Jochen.Baier at stud.uni-karlsruhe.de
Tue Mar 29 09:24:46 PST 2005
Quoting Joel Dice <dicej at mailsnare.net>:
> On Tue, 29 Mar 2005, Norberto Bensa wrote:
>
> > Joel Dice wrote:
> >> On Mon, 28 Mar 2005 Yossi.Itzkovich at ecitele.com wrote:
> >>> I have few X applications, started from the command line with identical
> >>> command line, but each has a different DISPLAY environment variable.
> >>> Is there a way to get the process id of a process from its window ?
> >>
> >> I asked about this a few months ago, and apparently it's not possible.
> >> What do you need the process id for? Perhaps what you're trying to do
> can
> >> be accomplished some other way.
> >
> > Maybe I'm a bit off-topic here, but perhaps you should take a look at
> xkill
> > code.
>
> Good idea. Unfortunately, xkill just calls XKillClient(Display,XID),
> which does not give you access to the PID.
hi,
maybe this is what you looking for:
gint get_pid (Window w)
{
Atom actual_type;
int actual_format;
unsigned long nitems, leftover;
unsigned char *pid_return;
gint pid=0;
int status;
gint err;
Atom net_wm_pid=XInternAtom(GDK_DISPLAY(), "_NET_WM_PID", False);
gdk_error_trap_push();
status=XGetWindowProperty(GDK_DISPLAY(), w,
net_wm_pid, 0,
1, False, XA_CARDINAL, &actual_type,
&actual_format, &nitems, &leftover, &pid_return);
err=gdk_error_trap_pop();
if (err!=0 || status != Success)
return 0;
if (pid_return) {
pid=*(gint *) pid_return;
XFree(pid_return);
}
return pid;
}
(not all windows have this property set)
regards jochen
More information about the xorg
mailing list