This compells me to post a short perl script I've written avoid the race:
#!/usr/bin/perl -wThis script has helped me to prevent mrxvt from hanging or racing with XWin. Note the magic number 8 near the end. I hate magic numbers! If you know of the "correct" way to fix this whole issue, email me the details.
use strict;
# start X
system("XWin -nolock -multiwindow -clipboard -silent-dup-error &");
if ($? == -1) {
print "failed to execute: $!\n";
} elsif ($? & 127) {
printf "child died with signal %d, %s coredump\n",
($? & 127), ($? & 128) ? 'with' : 'without';
} else {
printf "child exited with value %d\n", $? >> 8;
}
# get the Windows process id (not the Cygwin pid)
my $process = "";
my $command = "";
while ($process !~ /\d+/) {
print "Waiting for WINPID ...\n";
$command = "ps -el";
open(PS, "$command 2>&1 |") or die "cant $command: $!";
my($i, $column);
my @line = split /\s+/, <PS>;
for $i ( 0 .. $#line) {
if ($line[$i] eq "WINPID") {
$column = (scalar(@line) - $i) * -1;
}
}
while (<PS>) {
next unless /XWin/;
@_ = split;
$process = $_[$column];
print "WINPID = $process\n";
}
close PS or die "bad $command: $! $?";
}
my $xWinSockets = 0;
while ($xWinSockets < 8) {
sleep 1;
$xWinSockets = getNumberOfXWinSockets();
print "NumberOfXWinSockets = $xWinSockets\n";
}
system("mrxvt -sb -sl 1000 -fn fixed -fg green -bg black -g 150x45 --highlightColor green -ls &");
sub getNumberOfXWinSockets {
my $number = 0;
$command = "netstat -nao -p TCP";
open(STATUS, "$command 2>&1 |") or die "cant $command: $!";
while (<STATUS>) { / ${process}.$/ and do { $number++; } }
close STATUS or die "bad command: $! $?";
return $number;
}
Make sure your DISPLAY environment variable is set ... maybe "export DISPLAY=:0". I usually put a line something like that in my .bash_profile.
Here is the typical output from the perl script above:
$ x.plNotice how it was "Waiting for WINPID ..." several times ... not good. Anyone have any ideas about how to fix this?
child exited with value 0
Waiting for WINPID ...
Waiting for WINPID ...
Waiting for WINPID ...
Waiting for WINPID ...
WINPID = 2404
NumberOfXWinSockets = 0
NumberOfXWinSockets = 0
NumberOfXWinSockets = 0
NumberOfXWinSockets = 0
NumberOfXWinSockets = 0
NumberOfXWinSockets = 2
NumberOfXWinSockets = 2
NumberOfXWinSockets = 8
$
1 comment:
For anyone getting the "Fatal server error:
Can't read lock file /tmp/.X0-lock" ... I have updated the above script to use the "-nolock" option suggested everywhere on the net when you google the error.
Hope that helps.
Post a Comment