Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 05-31-2005, 03:29 PM   #1
LQ Newbie
Registered: Mar 2004
Posts: 17

Rep: Reputation: 2
Advanced question: finding pid of an x window

Hi.. I'm running X, and I want to find the process id of a program on the screen so that I can strace it.

However, the closest I've come is finding xkill, which works by telling the X server to close that connection, which usually (always?) kills the process that put the screen there.

I've found xwininfo and xlsclients commands, but they don't seem to have pid information.

I know that X isn't supposed to know the pid of processes talking to it, but I'm sure that if I knew the connection details I could use netstat -p or lsof | grep to find the actual process.

So, do you have any ideas?
Old 05-31-2005, 03:34 PM   #2
Registered: Apr 2004
Distribution: Slackware 11.0, Gentoo
Posts: 252

Rep: Reputation: 31
ps -aux | grep <name_of_program>

If that doesn't find it (the process name is different than the program name), then just do ps -aux and try to find the program.
1 members found this post helpful.
Old 05-31-2005, 05:12 PM   #3
LQ Newbie
Registered: Mar 2004
Posts: 17

Original Poster
Rep: Reputation: 2
Ok, let me give you some more detail.

The program is 'up2date', and 'ps aux | grep up2date' found these three processes:
root 3181 0.0 0.7 12672 3856 ? SN 12:57 0:00 up2date
root 3182 0.0 0.2 5020 1216 ? SN 12:57 0:00 /usr/sbin/userhelper -w up2date
root 3183 1.1 14.1 79072 68504 ? RN 12:57 1:16 /usr/bin/python -u /usr/sbin/up2date

One (or more) of these three has the window open. As it stands, I'd have to kill them off one by one to determine which one has the window I'm interested in. In addition, if I kill off one of them, the others might quit as well.

In short, I'm guessing. I don't like guessing, it's not very scientific.

For every window on the screen, we know there is a definite process id behind it. We just don't know how to go from window-id to process-id, short of killing stuff and seeing what's left.

The goal for today is to make 'up2date' use a server on the same continent as I'm on, but to do that I need to strace it to find out where it gets its configuration from. Right now I'm in Canada and it's getting files from Czechoslovakia(!), and the speed is not good. I'm going to fix it to find the closest (ping-wise) server and use that. I might even go so far as to find the best bandwidth, but that's a more tedious problem to solve.

The long term goal is to figure out how to track down a process id from a window, in case the name of the program is unknown. This would come in handy if some hacker were to get onto my system and pop up a window on my screen, as typically they try and hide their programs with unrelated names (So that "ps aux | grep hackerprocess" doesn't work).
Old 05-31-2005, 05:36 PM   #4
LQ Newbie
Registered: Mar 2004
Posts: 17

Original Poster
Rep: Reputation: 2
Found it

Ok, I found the command: xprop

If you do 'xprop _NET_WM_PID' and then click on the window, it will tell you the pid.

You can also say 'xprop -id 0x2200019 _NET_WM_PID' if you know the id of the window already.
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
logging off by script or finding PID of session bob_man_uk Red Hat 6 10-27-2005 03:37 AM
/var/run/[XXX].pid - Tcl pid code liguorir Linux - Software 1 05-20-2004 10:32 PM
finding pid with program name durden2.0 Linux - Newbie 1 08-04-2003 08:38 PM
Finding the first pid corrierich Linux - General 2 03-06-2003 02:43 AM
finding a PID and killing it tangle Linux - General 3 01-25-2003 10:14 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:15 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration