Subject: | /proc/$pid/environ interaction |
Hello, I was curious if you it would be possible to have Sys::Proctitle
maintain the integrity of the environment as seen in Linux procfs.
I was trying to use '/proc/$pid/environ' to track a value in the
environment for all running scripts, and found that it was corrupt for
some. I eventually tracked it down to changing $0, and thought I'd see
if Sys::Proctitle might preserve 'environ'. It ended up having the same
issue.
The script below demonstrates the issue. Once I call setproctitle(),
'environ' and 'ps e' output is mostly control characters and spaces. For
me it outputs:
Show quoted text
> perl env_test.pl
7851 4311 4395 4495
7851 4311 0 26
I've confirmed this behavior in perl 5.8.9 and 5.14.1. I'm running on
Linux 2.6.9-78.0.1.ELhugemem #1 SMP Tue Jul 22 18:23:25 EDT 2008.
Thanks!
- danboo
use Sys::Proctitle;
env_size();
Sys::Proctitle::setproctitle('different');
env_size();
sub env_size
{
print join " ",.
$$,
visible_size( %ENV ),
visible_size( `cat /proc/$$/environ` ),
visible_size( `ps ehww $$` ),
"\n";
}
sub visible_size
{
my $s = join '', @_;
$s =~ s/[[:cntrl:][:space:]]+//g;
return length $s;
}