If I run these commands:
... geany --new-instance --no-msgwin --no-session --no-terminal -c pathtoconfig/ & pid=$! echo $pid wmctrl -lp read -p "waiting..." ... the resulting PID does not match that of the geany process launched. But if a sleep 1 command is inserted before reading the PID (after the geany line), then the PID is correct. The reason for this is that windowing takes some time, so wmctrl -lp provides preliminary information which does not much precisely the right PID. What would be the best way to wait for geany to complete launching before the new window has stabilized and wmctrl is aware of it?
Update: - Run on Lubuntu 16.04 / HP ProBook 6360b.
Actual PID for comparison was obtained with
wmctrl -lpthat includes PID in the list.PID is fetched correctly by
$!, what takes some time to update is the one provided bywmctrl -lp, that is different after some time (some 0.27s forgeany, some 0.16s forleafpad), as if the window manager would take some time to update the PID.
geanythis two ways:geany &andgeany --new-instance --no-msgwin --no-session --no-terminal &. Did the problem remained?geany &(it does get the correct PID). Then tried several alternatives, removing some options (doesn't get the correct PID), and finally the simplified one again (and now, does NOT get the correct PID). This was done isolating the piece of code, to make sure that it only relies on launchinggeany.geanylaunching time, does not matter because of how fork–exec works. And another helpful answer about&operator: process in the background. By the way, how you get second PID for comparing?geany &the PID after settling is 11078,$!got 11118, withleafpadwas 11078, and$!got 11173. In both cases, the PID matches perfectly whensleep 1is added. So, in principle it doesn't seem to be related to launching time, but waiting for some time actually helps.geany &will work fine for a delay of 0.27s, whileleafpad &does work for delays over 0.16s. Something is going on after the program is launched. (Technical data added to the question.)