Review your favorite Linux distribution.
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 10-29-2007, 08:37 PM   #1
Registered: Sep 2007
Posts: 36

Rep: Reputation: 15
Something like xkill, but just output the PID or resource ID, don't kill

I want to write a script to do some things to processes which are producing specific windows. I want the user to be able to select a window. So I'm looking for a program which is basically just like xkill, but rather than closing the X connection, I simply want it to output the PID of the parent (or the X resource ID, from which I can hopefully find the parent PID).

I've even gone so far as to find the xkill source, but I don't know C, so that approach stopped there.
Old 10-29-2007, 08:58 PM   #2
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
I wrote a little script to do just this for my own use. Save this to a file called "xpid", make the file executable and put it in your path:

wid=$(xwininfo  |grep 'Window id:' |cut -d" " -f4)
pid=$(xprop -id "$wid" |grep "^_NET_WM_PID" | cut -d" " -f3)

echo $pid |grep '^ *[0-9][0-9]* *$' && exit 0

cat <<EOF 1>&2
xpid ERROR: can't get PID for selected window.
            window ID:   $wid
            pid: $pid
exit 1
Old 10-29-2007, 11:28 PM   #3
Registered: Sep 2007
Posts: 36

Original Poster
Rep: Reputation: 15
Thanks a lot! That's a great little script, will be very handy.


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
kill <pid> does not do anything moskito01 Linux - General 9 08-25-2009 01:20 PM
kill -9 and respawns as new pid jago25_98 Linux - Software 3 06-18-2007 03:05 PM
kill pid ekdya Debian 3 04-18-2006 06:04 PM
kill pid.... won't work with 'pid' variable given.. sachitha Programming 6 03-06-2006 08:48 PM
Why Does the Program Die When I xkill It But Not When I kill -9 It? LinuxGeek Linux - Software 3 01-03-2005 04:30 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:00 PM.

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