jason_s has asked for the wisdom of the Perl Monks concerning the following question:
I have a test script that takes an exclusive lock on a file, and then just goes into an infinite loop:#!/usr/bin/perl -w use strict; my $pid=$ARGV[0]; my $trace_out; my $strace_pid; eval { local $SIG{ALRM} = sub { kill 2, $strace_pid || warn "couldn't kill $strace_pid: $!"; close STRACE or die "couldn't close strace"; die "exiting eval"; }; $strace_pid = open (STRACE,"strace -q -p$pid 2>&1|") or die "couldn' +t open strace"; alarm (1); undef $/; $trace_out=<STRACE> ; }; print "traceout is $trace_out";
If I run two instances of this, (the first instance gets the lock, the 2nd blocks while waiting for a lock), and attach strace to them, here's what I see:#!/usr/bin/perl use Fcntl ':flock'; open FH, "file.txt" ; flock FH, LOCK_EX or die "couldn't lock"; while (true) {};
As expected, pid 17289 has no strace output, since it's just looping. And 17290 is blocking attempting to take a lock.>./locker.pl & [1] 17289 >./locker.pl & [2] 17290 >strace -q -p17289 >strace -q -p17290 flock(3, LOCK_EX <unfinished ...>
My intention is that the output should be:./hang_finder 17290 traceout is
Obviously,I'm doing something wrong, but I can't figure out what . . .traceout is flock(3, LOCK_EX
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Calling strace from a perl program
by ikegami (Patriarch) on Mar 11, 2008 at 07:44 UTC | |
|
Re: Calling strace from a perl program
by cdarke (Prior) on Mar 11, 2008 at 08:31 UTC | |
by ikegami (Patriarch) on Mar 11, 2008 at 21:56 UTC | |
|
Re: Calling strace from a perl program
by zentara (Cardinal) on Mar 11, 2008 at 12:48 UTC | |
by jason_s (Acolyte) on Mar 11, 2008 at 23:51 UTC | |
|
Re: Calling strace from a perl program
by pc88mxer (Vicar) on Mar 11, 2008 at 21:00 UTC | |
by jason_s (Acolyte) on Mar 11, 2008 at 23:59 UTC | |
by kyle (Abbot) on Mar 11, 2008 at 21:27 UTC | |
by pc88mxer (Vicar) on Mar 11, 2008 at 21:39 UTC |