LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 10-29-2007, 07:37 PM   #1
musther
Member
 
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, 07:58 PM   #2
matthewg42
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:
Code:
#!/bin/bash

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
EOF
exit 1
 
Old 10-29-2007, 10:28 PM   #3
musther
Member
 
Registered: Sep 2007
Posts: 36

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


Reply



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 12:20 PM
kill -9 and respawns as new pid jago25_98 Linux - Software 3 06-18-2007 02:05 PM
kill pid ekdya Debian 3 04-18-2006 05:04 PM
kill pid.... won't work with 'pid' variable given.. sachitha Programming 6 03-06-2006 07: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 03:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:09 AM.

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