从 CGI 脚本调用时 Mono 挂起
我有一个用 C# 编写的程序,需要从 CGI 脚本调用它。
当我从 python 或 bash CGI 脚本调用程序时:
#!/bin/bash
echo Content-type: text/plain
echo
echo
/home/<user>/.mono/bin/mono HelloWorld.exe
或者
#!/usr/bin/python
import subprocess
print 'Content-type: text/plain\n\n'
p=subprocess.Popen(['/home/<user>/.mono/bin/mono','HelloWorld.exe'], stdout=subprocess.PIPE)
print p.stdout.read().strip('\r\n')
进程挂起并且浏览器无限期地等待响应。正如您所注意到的,我在我的主目录中“安装”了 mono,因为我没有 root 权限。它是在服务器上编译的,可执行文件就位于该目录中,但它似乎对其他所有内容都工作得很好。
使问题令人困惑的是:
- 如果我自己调用命令或 cgi 脚本,则不会出现问题。来自 SSH 会话。
- 问题似乎发生在程序运行后:如果我将结果通过管道传输到文件,结果将出现在文件文件中,单声道似乎在完成后挂起。
- 在我的 Mac 笔记本电脑上,如果使用相同的 cgi 脚本和 .exe,但正确安装了 mono,则不会出现此问题。
- 如果脚本只调用 mono 例如,则不会出现问题。 (
subprocess.Popen(['/home/
) - mono 只是打印标准的“你给我的”无事可做”消息并正常退出。/.mono/bin/mono'], stdout=subprocess.PIPE) - 任何 .exe 都会出现此问题,无论它只是 hello world 还是进行一些相对复杂的计算(这就是我的实际程序所做的)。
我尝试将 MONO_SHARED_DIR 设置为全局可写的目录,因为我最初认为这与 fake-root 看到的问题相同,请参阅 Mono 常见问题解答页面。
gdb
给出以下输出:
Loaded symbols for /lib/libpthread.so.0
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /lib/libnss_compat.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/libnss_compat.so.2
Reading symbols from /lib/libnsl.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/libnsl.so.1
Reading symbols from /lib/libnss_nis.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/libnss_nis.so.2
Reading symbols from /lib/libnss_files.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/libnss_files.so.2
0x00007f85d7680b50 in sem_wait () from /lib/libpthread.so.0
我用谷歌搜索了最后一行和 sem_wait
但我找不到任何相关内容,因为这似乎是一个常见问题。
对于这个问题的任何帮助将非常感激,我真的不想用 C# 重写我的整个程序。
版本信息:
- 操作系统:Ubuntu 10.04.3 LTS
- Mono:Mono JIT 编译器版本 2.10.2(tarball Sat Jun 18 15:11:20 BST 2011)
- Apache:Apache/2.2.14 (Ubuntu)
I have a program written in C# which I need to call from a CGI script.
When I call the program from either a python or bash CGI script:
#!/bin/bash
echo Content-type: text/plain
echo
echo
/home/<user>/.mono/bin/mono HelloWorld.exe
or
#!/usr/bin/python
import subprocess
print 'Content-type: text/plain\n\n'
p=subprocess.Popen(['/home/<user>/.mono/bin/mono','HelloWorld.exe'], stdout=subprocess.PIPE)
print p.stdout.read().strip('\r\n')
the process hangs and the browser waits indefinitely for a response. As you will have noticed I have mono "installed" in my home directory as I don't have root privileges. It was compiled on the server and the executable is just sitting in that directory, but it seems to work fine for everything else.
What makes the problem confusing is:
- The problem doesn't occur if I call the command or indeed the cgi script myself eg. from an SSH session.
- The problem seems to occur after the program has run: if I pipe the results to a file the results appear in the file file, mono just seems to hang after it's finished.
- The problem doesn't occur on my mac laptop with the same cgi script and .exe but with mono properly installed.
- The problem doesn't occur if the script just calls mono eg. (
subprocess.Popen(['/home/<user>/.mono/bin/mono'], stdout=subprocess.PIPE)
) - mono just prints the standard "you've given me nothing to do" message and exits normally. - The problem occurs with any .exe whether it is just hello world or making some relatively complex calculations, which is what my actual program does.
I've tried setting MONO_SHARED_DIR
to a directory that is world writable as I originally thought this was the same problem as that seen with fake-root see the Mono FAQ page.
gdb
gives the following output:
Loaded symbols for /lib/libpthread.so.0
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /lib/libnss_compat.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/libnss_compat.so.2
Reading symbols from /lib/libnsl.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/libnsl.so.1
Reading symbols from /lib/libnss_nis.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/libnss_nis.so.2
Reading symbols from /lib/libnss_files.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/libnss_files.so.2
0x00007f85d7680b50 in sem_wait () from /lib/libpthread.so.0
I've googled the last line and sem_wait
but I can't find anything relevant as this seems to be a common problem.
Any help on this problem would be very much appreciated, I really don't want to rewrite my whole program in C++ from C#.
Version information:
- OS: Ubuntu 10.04.3 LTS
- Mono: Mono JIT compiler version 2.10.2 (tarball Sat Jun 18 15:11:20 BST 2011)
- Apache: Apache/2.2.14 (Ubuntu)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
大多数人可能对这个答案不感兴趣,但为了完整起见,我应该提供它。
运行我使用的服务器的 Retrosnub 有一个单独的 Web 服务器和 ssh 服务器。显然我已经在 ssh 服务器上编译了 mono,但是当我尝试从 CGI 脚本调用它时,它是由 Web 服务器执行的。 Web 服务器具有不同的架构(32 位而不是 64 位),这导致了所有问题。
The answer probably isn't interesting to most people, but for completeness I should provide it.
Retrosnub who run the server I was using have a separate web server and ssh server. I had obviously compiled mono on the ssh server, but when I tried calling it from a CGI script it was being executed by the web server. The web server has a different architecture (32bit not 64bit) which caused all the problems.