tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

$$ broken??



I have a weird situation which looks as though $$ is broken in sh.

This is on a 5.2 amd64 machine.

My rc.local begins with some code to adjust resource limits:

thispid=$$
for pid in 1 $thispid
do
        ...use sysctl -w proc.$pid.rlimit.etc...
done

However, daemons started later in /etc/rc.local were getting the
original resource limits, even though the sysctl -w commands were
printing out suitable changed limits for PIDs 1 and 2.

I finally resorted to the sledgehammer of running
"ktrace -i -d -f ... -p 1" at the very beginning of rc.local, with
"sleep 5" and "ktrace -C" at the end.  The resulting ktrace file made
it clear the script was being run by PID 279, not 2.  Checking with ps,
I see four "sh /etc/rc autoboot" processes, one of which is PID 2 and
another of which is PID 279.

The real question I have here is, why is $$ in rc.local giving me the
wrong value?  As I understand it, it should give me the process ID of
the process running the script, not the process ID of a different
process somewhere up the process parenting tree.

Perhaps more importantly, what can I do to fix it?  Failing that, is
there some other tool I can use to give me the correct PID as a
workaround?

/~\ The ASCII                             Mouse
\ / Ribbon Campaign
 X  Against HTML                mouse%rodents-montreal.org@localhost
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Home | Main Index | Thread Index | Old Index