Just want to know WNOHANG...

package MyApp;
# I just want to know WNOHANG from sys_wait_h ... [-;

our $WNOHANG_VALUE ||= `$^X -MPOSIX=:sys_wait_h -e "print WNOHANG;"`;


sigh maybe useful for a long-time running program if you are sensitive to memory usage..


Why do you need to start up a whole new process just to get a constant?

Friedo, he wants to avoid loading POSIX.pm in the current process, since it's a rather large module, and usually ends up consuming several megabytes of memory.

I can see how that could be a concern if you have a long-running process, especially something that does pre-forking, or you're in a memory-constrained environment.

Obviously, in most cases this won't be an issue, and I hope that no one adopts this technique without making 100% sure it's necessary.

Maybe a better way would be to put this logic in a build/install script, which would define the constants in a config file that gets installed with the module. That way at least you don't have to execute the same hackery every runtime.

POSIX.pm is actually not so large, since it uses AutoLoader to dynamically choose only necessary bits of code.

$ wc -l /usr/lib/perl/5.8/auto/POSIX/*.al | tail -1
2096 total
$ wc -l /usr/lib/perl/5.8/POSIX.pm
61 /usr/lib/perl/5.8/POSIX.pm

Leave a comment

About Myoungjin Jeon

user-pic JG's blog for perl (-; I'm a chef and enjoying coding for my life.