Rambles around computer science

Diverting trains of thought, wasting precious time

Tue, 29 Sep 2009

Shell Gotme number 1 -- the Heisenbergian process trees

On my Lab machine, the X login system doesn't clean up stray child processes that your X session may have left behind. (I've a feeling the Debian xinit scripts do this, but I'm not sure.) This was bothering me, because I start some background jobs in my .xsession which I want to die naturally when the session ends. So I put the following towards the end of my .xsession.

echo -n "End of .xsession: detected living child pids: " 1>&2
ps --no-header f -o pid --ppid $$ | \
	while read pid; do kill ; done 2>/dev/null

Unfortunately, I found that those pesky children were still alive. (Can you tell what's wrong? Yes, that's right.) Both the ps process and the while subshell are among the children which are being killed. So one way or another, the pipeline gets broken before the loop has managed to kill the children I actually wanted to kill. A version which doesn't suffer this problem is as follows.

child_pids=$( ps --no-header f -o pid --ppid $$ )
for pid in ; do kill  2>/dev/null; done

It's another instance of the familiar Heisenbergian nature of inspecting process trees from the shell: doing many basic things from the shell entails creating processes, so inspecting the shell's own process tree is likely to yield perturbed results. Usually it's just an unwanted entry in ps (as with the old ps | grep foo gotcha) but the above shows it sometimes causes subtler problems.

[/devel] permanent link contact

Standalone ksmserver, part 2: getting it right

I blogged previously about my attempts to use KDE's session manager in a standalone fashion (with fvwm, in my case). What I presented there isn't entirely satisfactory, mainly because not all window sizes and positions get restored when restoring the session. I've finally worked out why. Unfortunately, this has also revealed that some content in the previous post is wrong. Allow me to correct myself here.

So, all you need in your fvwm config is something like the following.

AddToFunc SessionInitFunction
 + I Exec dcop klauncher klauncher autoStart 3; \
dcop ksmserver ksmserver autoStart0Done; \
dcop ksmserver ksmserver kcmPhase1Done; \
dcop ksmserver ksmserver autoStart1Done; \
dcop ksmserver ksmserver kcmPhase2Done; \
sleep 4; dcop ksmserver ksmserver autoStart2Done

# assuming you quit using a Quit-Verify menu...
AddToMenu Quit-Verify   "Quit"  SaveQuitSession

[/devel] permanent link contact


Powered by blosxom

validate this page