问题
Unfortunately, my question is not as simple as keeping track of two windows created by the same process.
Here is what I have:
- Two users, Jack and Jim are remotely logged in to the same Unix system and run X servers
- Jack runs an application, 'AwesomeApp', that opens a GUI in a X window
- Jim runs another instance of this application, opening his own GUI window
- Now, Jack runs a supervisor application that will communicate with the process owning the first window (eg 'AwesomeApp') because it's HIS instance of 'AwesomeApp'
- How can his instance of the supervisor find which instance of 'AwesomeApp' window is his own?
Aaaahhhh...looking it up on a per-user basis yes that could work. As long as I tell the users that they cannot log in with the same user account from two different places.
回答1:
You can use pgrep to get the process ID of Jack's instance of AwesomeApp:
pgrep -u Jack AwesomeApp
So if you launch the supervisor application from a shell script, you could do something like the following:
AWESOME_ID=`pgrep -u $USER AwesomeApp 2>/dev/null`
# run the supervisor application and pass the process id as the argument
supervisor $AWESOME_ID
Alternatively, if you don't want to use external programs like pgrep or ps, you could always try looking for the process in /proc directly.
来源:https://stackoverflow.com/questions/60967/how-do-i-keep-track-of-related-windows-in-x11