Hi,
Most (all ?) linux distros have scripts that run at boot time that remove files from these directories. This is partly housekeeping and partly because rogue lock files, etc., may prevent tasks from being started. The code is probably in /etc/rc.d/rc.sysinit or /etc/rc.d/rc.boot depending on which linux you have. Its not quite as simple as deleting everything in those directories because you need some files to be there - notably /var/run/utmp to enable logins. A example from a caldera rc.boot is as follows :
[snip]
echo -n "Cleaning up:"
if [ "`echo "$TMPTTL" | sed -n 's/^[0-9][0-9]*$/OK/p'`" = "OK" ]; then
# Wipe /tmp (and don't erase `lost+found', `quota.user' or `quota.group')!
# Note that files _in_ lost+found _are_ deleted.
echo -n " /tmp"
( cd /tmp && find . -xdev ! -ctime -$TMPTTL ! -name . ! \( -name lost+found -uid 0 \) ! \( -name quota.user -uid 0 \) ! \( -name quota.group -uid 0 \) -depth -exec rm -rf -- {} \; )
fi
echo -n " /var/lock"
# Clean up any stale locks.
# HACK ALERT! We need to save the 'subsys/network' lock...
mv -f /var/lock/subsys/network /var/adm/network.$$ 2> /dev/null
( cd /var/lock && find . -type f -exec rm -f -- {} \; )
# HACK ALERT! We need to restore the 'subsys/network' lock...
mv -f /var/adm/network.$$ /var/lock/subsys/network 2> /dev/null
# Load the random generator.
if [ -c /dev/urandom -a -f /var/run/random-seed ]; then
cat /var/run/random-seed > /dev/urandom
fi
echo -n " /var/run"
# Clean up /var/run and create /var/run/utmp so that we can login.
( cd /var/run && find . ! -type d -exec rm -f -- {} \; )
: > /var/run/utmp
[snip]
Others may be simpler / more complex even.
Quite why your's freezes is a good question. I can only suggest that you amend the code to ascertain where the problem is - firstly simply by adding a few appropriate 'echo' statements after each chunk of code to see where it hangs.
Hope this helps