从 system() 调用 ksh 脚本导致段错误
我有一个经过相当好的测试的应用程序,我正在尝试在 Ubuntu Linux 上运行,但遇到了很多问题,似乎与 ksh 实现有关。当系统构建命令调用它时,问题似乎就会显现出来。
有一个 ksh 脚本可以从 C 源文件自动生成 C 头文件。当我尝试通过 C 应用程序中的 system()
调用运行它时,ksh 因段错误而崩溃。
在命令行中,我可以毫无问题地运行该命令,并且它可以正常工作。在我使用过的所有其他平台(包括 SLES 和 Fedora Linux)上,它也可以在相同的情况下工作。我还可以通过将脚本中的 shebang 行更改为 #! 来使其工作。 /bin/bash
(它所做的大部分工作实际上是在 sed 脚本中进行的,因此 shell 脚本中不会执行任何外来命令)。
但我们已经对 ksh 进行了标准化,主要是因为它是我们仍然支持的旧 AIX 版本上可用的最佳 shell,并且如果默认情况下不包含它,则很容易将其添加到 Linux 发行版中。
我不太确定在哪里看这个 - 有人见过类似的东西吗?
I've got a fairly well tested bit of an application I'm trying to get working on Ubuntu Linux, and having a lot of problems, seemingly with the ksh implementation. The problem seems to manifest when it is being called by the system build command.
There is a ksh script which auto-generates a C header file from a C source file. When I try to run it via a system()
call in a C application, the ksh crashes with a segfault.
At the command line, I can run the command without problems, and it works correctly. It also works in the same circumstances on all other platforms I've used (including SLES and Fedora Linux). I can also make it work by changing the shebang line in the script to #! /bin/bash
(most of the work it does is really in a sed script so no exotic commands are done in the shell script).
But we've standardised on ksh, mainly as it was the best shell available on older AIX versions that we still support, and it is easy to add to Linux distros if it isn't included by default.
I'm not too sure where to look on this - has anyone seen anything similar?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看是否可以通过将完整路径放入系统调用来解决问题。
如果在使用 ksh 时未在您预期的路径上找到它,这可能是问题的一部分。
See if you can fix the problem by putting the full path in the system call.
If its not finding on the path you anticipate when using ksh this could be part of the problem.
作为信息,我终于找出了导致问题的具体细节。最基本的方法是简单地打开 100 个指向同一文件的文件指针,然后调用
system()
例如,只要脚本 shebang 是 AT&T ksh shell,就可以在这一个机器上可靠地崩溃。我发现系统构建的一部分留下了许多指向一个文件的挂起文件指针。不足以解决 ulimit 问题,但足以解决这种奇怪的问题。
For info, I finally worked out the specifics causing the problem. The most basic way is simply to open 100 file pointers to the same file, then call
system()
e.g.As long as the script shebang is the AT&T ksh shell, that reliably crashes on this one box. I found a bit of the system build leaves lots of hanging file pointers to one file. Not enough to hit ulimit problems, but enough for this weirdness.