如何在适用于其子级的Perl脚本中设置ulimit? [英] How do I set a ulimit from inside a Perl script that applies to its children?

查看:99
本文介绍了如何在适用于其子级的Perl脚本中设置ulimit?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Perl脚本,该脚本执行各种安装步骤来为我们公司设置开发箱.它运行各种shell脚本,其中一些由于低于所需的ulimit s(在我的情况下,具体为栈大小-s)而崩溃.

I have a Perl script that does various installation steps to set up a development box for our company. It runs various shell scripts, some of which crash due to lower than required ulimits (specifically, stack size -s in my case).

因此,我想设置一个ulimit,该ulimit会应用于从我的主要Perl脚本中启动的所有脚本(children),但是我不确定如何实现这一点-任何尝试从中调用ulimit的尝试在脚本中仅将其设置在该特定的子外壳上,该外壳立即退出.

Therefore, I'd like to set a ulimit that would apply to all scripts (children) started from within my main Perl one, but I am not sure how to achieve that - any attempts at calling ulimit from within the script only set it on that specific child shell, which immediately exits.

我知道我可以在运行Perl脚本或使用/etc/security/limits.conf之前调用ulimit,但是我不希望用户知道任何这些-他们应该只知道如何运行脚本,这应该为他们照顾所有这些.

I am aware that I can call ulimit before I run the Perl script or use /etc/security/limits.conf but I don't want the user to know any of this - they should only know how to run the script, which should take care of all of that for them.

我也可以在每次运行命令时都运行ulimit,例如ulimit -s BLA; ./cmd,但是我不想每次都重复此操作,我觉得这里有一个更好,更干净的解决方案.

I can also run ulimit every time I run a command, like this ulimit -s BLA; ./cmd but I don't want to duplicate this every time and I feel like there's a better, cleaner solution out there.

另一个疯狂的解决方法"是创建一个名为BLA.sh的包装脚本,该脚本将设置ulimit并调用BLA.pl,但是,这又是我的主意,现在我有两个脚本(我什至可以BLA.pl用"ulimit -s BLA; ./BLA.pl --foo"来称呼自己,并根据是否看到--foo而采取不同的行动,但这比以前更骇人了.

Another crazy "workaround" is to make a wrapper script called BLA.sh which would set ulimit and call BLA.pl, but again, it's a hack in my mind and now I'd have 2 scripts (I could even make BLA.pl call itself with "ulimit -s BLA; ./BLA.pl --foo" and act differently based on whether it sees --foo or not but that's even hackier than before).

最后,显然我可以安装BSD :: Resource,但是我想避免使用外部依赖项.

Finally, apparently I could install BSD::Resource but I'd like to avoid using external dependencies.

那么,在Perl脚本中设置ulimit并将其应用于所有子级的 方法是什么?

So what is THE way to set the ulimit from within a Perl script and make it apply to all children?

谢谢.

推荐答案

我最终在ulimit -s BLA之前添加了需要它的命令.我特别不想使用BSD :: Resource,因为它不是默认的Perl软件包,并且大约一半的现有开发机器都缺少它.没有用户交互是特定要求.

I ended up prepending ulimit -s BLA to the commands that needed it. I specifically didn't want to go with BSD::Resource because it's not a default Perl package and was missing on about half of the existing dev machines. No user interaction was a specific requirement.

这篇关于如何在适用于其子级的Perl脚本中设置ulimit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆