Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 53633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:05:38+00:00 2026-05-10T17:05:38+00:00

Under Linux, my C++ application is using fork() and execv() to launch multiple instances

  • 0

Under Linux, my C++ application is using fork() and execv() to launch multiple instances of OpenOffice so as to view some powerpoint slide shows. This part works.

Next I want to be able to move the OpenOffice windows to specific locations on the display. I can do that with the XMoveResizeWindow() function but I need to find the Window for each instance.

I have the process ID of each instance, how can I find the X11 Window from that ?


UPDATE – Thanks to Andy’s suggestion, I have pulled this off. I’m posting the code here to share it with the Stack Overflow community.

Unfortunately Open Office does not seem to set the _NET_WM_PID property so this doesn’t ultimately solve my problem but it does answer the question.

// Attempt to identify a window by name or attribute. // by Adam Pierce <adam@doctort.org>  #include <X11/Xlib.h> #include <X11/Xatom.h> #include <iostream> #include <list>  using namespace std;  class WindowsMatchingPid { public:     WindowsMatchingPid(Display *display, Window wRoot, unsigned long pid)         : _display(display)         , _pid(pid)     {     // Get the PID property atom.         _atomPID = XInternAtom(display, '_NET_WM_PID', True);         if(_atomPID == None)         {             cout << 'No such atom' << endl;             return;         }          search(wRoot);     }      const list<Window> &result() const { return _result; }  private:     unsigned long  _pid;     Atom           _atomPID;     Display       *_display;     list<Window>   _result;      void search(Window w)     {     // Get the PID for the current Window.         Atom           type;         int            format;         unsigned long  nItems;         unsigned long  bytesAfter;         unsigned char *propPID = 0;         if(Success == XGetWindowProperty(_display, w, _atomPID, 0, 1, False, XA_CARDINAL,                                          &type, &format, &nItems, &bytesAfter, &propPID))         {             if(propPID != 0)             {             // If the PID matches, add this window to the result set.                 if(_pid == *((unsigned long *)propPID))                     _result.push_back(w);                  XFree(propPID);             }         }      // Recurse into child windows.         Window    wRoot;         Window    wParent;         Window   *wChild;         unsigned  nChildren;         if(0 != XQueryTree(_display, w, &wRoot, &wParent, &wChild, &nChildren))         {             for(unsigned i = 0; i < nChildren; i++)                 search(wChild[i]);         }     } };  int main(int argc, char **argv) {     if(argc < 2)         return 1;      int pid = atoi(argv[1]);     cout << 'Searching for windows associated with PID ' << pid << endl;  // Start with the root window.     Display *display = XOpenDisplay(0);      WindowsMatchingPid match(display, XDefaultRootWindow(display), pid);  // Print the result.     const list<Window> &result = match.result();     for(list<Window>::const_iterator it = result.begin(); it != result.end(); it++)         cout << 'Window #' << (unsigned long)(*it) << endl;      return 0; } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:05:39+00:00Added an answer on May 10, 2026 at 5:05 pm

    The only way I know to do this is to traverse the tree of windows until you find what you’re looking for. Traversing isn’t hard (just see what xwininfo -root -tree does by looking at xwininfo.c if you need an example).

    But how do you identify the window you are looking for? Some applications set a window property called _NET_WM_PID.

    I believe that OpenOffice is one of the applications that sets that property (as do most Gnome apps), so you’re in luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 113k
  • Answers 113k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The Mangifier accessibility tool in Windows Vista used to be… May 11, 2026 at 10:08 pm
  • Editorial Team
    Editorial Team added an answer You can do something like this if don't need access… May 11, 2026 at 10:08 pm
  • Editorial Team
    Editorial Team added an answer You can write a macro in VBA to handle doing… May 11, 2026 at 10:08 pm

Related Questions

Is there a manual for cross-compiling a C++ application from Linux to Windows? Just
I am creating a C++ SDL game engine, and it is relevant to know
So I'm running PPP under linux with a cellular modem. The program I'm writing
I'd like to port an application written under linux to windows. Currently I'm using

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.