Mex - 执行命令 'which gcc' 挂起

Mex - Executing command 'which gcc' hangs

我在编译 .c mex 文件时遇到问题。特别是,我不知道它是否需要很长时间来编译(这是一个非常大的程序,约 60MB 的代码),或者它是否配置错误或有其他问题。

我在 Ubuntu 12.04 64 位,MATLAB 2015a,配置了 gcc。我的 c 文件名为 test4.c.

所以,我 运行:

mex -v test4.c

Verbose mode is on.
Neither -compatibleArrayDims nor -largeArrayDims is selected.
     Using -compatibleArrayDims. In the future, MATLAB will require the use of
     -largeArrayDims and remove the -compatibleArrayDims option.
     For more information:
     http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
... Looking for compiler 'gcc' ...
... Executing command 'which gcc' ...

这就是我得到的全部。如果它正在做更多的事情,我希望详细模式会打印它。

正在编译吗?我怎么知道?为什么它会卡在这里("which gcc" 在做什么?

命令 which gcc 通常只会告诉您 gcc 在系统上的安装位置,这应该相当快。您可以从 shell 自己尝试确认:

pax> which gcc
/usr/bin/gcc

所以如果这真的需要很长时间才能完成,我会感到非常惊讶。

找出答案的最好方法可能是打开终端并输入命令,将您的用户名放在 <user>:

的位置
ps -fu<user> >/tmp/pslist.txt

在我的例子中,那将是 ps -fupax

这将为您提供所有进程的列表,然后您可以使用它来追踪树中当前是哪个进程 运行,例如:

UID        PID  PPID  C STIME TTY          TIME CMD
pax       3103  3099  0 11:42 pts/0    00:00:00 bash
pax       3137  3103  0 11:48 pts/0    00:00:00 ps -f

首先找到 mex -v test4.c 进程(在 CMD 下)并获取它的进程 ID (PID)。从那里,您可以查找在父进程 ID (PPID) 字段中具有相同编号的所有进程。在我上面的例子中,bash 进程是 ps 进程的父进程。

如果您沿着树向下走足够远,就会发现您的错误进程。假设它的寿命相对较长,那么在检查 ps 输出时相隔二十秒(例如)时,它仍然存在 - 它也更有可能消耗了更多 CPU 时间,因此您可以查看在非零条目的 TIME 列中。