我有一个使用popen和的程序pclose:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/wait.h>
int main(void)
{
FILE *fp = NULL;
int ret_val = 0;
fp = popen("ls *", "r");
if (NULL == fp)
{
printf("popen error\n");
return 1;
}
ret_val = pclose(fp);
if (-1 == ret_val)
{
printf("pclose error\n");
return 1;
}
else
{
printf("%d,%d,%d\n",ret_val, WIFEXITED(ret_val), WEXITSTATUS(ret_val));
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
该计划的输出是:
./test
Broken Pipe
36096,1,141
Run Code Online (Sandbox Code Playgroud)
我的问题是:
我的应用程序是一个在 Solaris 上运行的多线程程序。
最近,我发现它可能会崩溃,原因是指针数组中的一个成员从有效值更改为NULL,所以在访问它时,它崩溃了。
由于出现比例很低,近2个月只出现了两次,而且数组中变化的成员并不相同。我找不到重复的步骤,并且在检查代码后,没有得到任何有价值的线索。
任何人都可以就如何调试内存随机更改问题提供一些建议吗?
我想打印探测器被触发的时间.检查Dtrace文档后,我找到了内置变量:walltimestamp.而Dtrace脚本喜欢这样:
pid$1::func:entry
{
trace(walltimestamp);
}
Run Code Online (Sandbox Code Playgroud)
但是walltimestamp"自1970年1月1日00:00世界协调时间以来的当前纳秒数",所以输出喜欢"1389583988106535481".我认为这对用户来说并不容易理解,并希望输出像"Mon Jan 13 00:00:00 2014".我搜索过Dtrace是否提供类似ctimeC编程语言的功能,但没有找到.
有没有人需要自己实现像ctime这样的功能?或者有更好的方法来显示时间吗?
我下载GDC的Linux,并尝试建立一个简单的D程序。执行“ gdc hello.d -o hello”后,输出:
[root@localhost nan]# gdc hello.d -o hello
/usr/bin/ld: unrecognized option '-plugin'
/usr/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
然后,我使用“ gdc -v hello.d -o hello”命令,并尝试查找根本原因。它显示:
......
COLLECT_GCC_OPTIONS='-v' '-o' 'hello' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/home/nan/x86_64-gdcproject-linux-gnu/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/collect2 -plugin /home/nan/x86_64-gdcproject-linux-gnu/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/liblto_plugin.so -plugin-opt=/home/nan/x86_64-gdcproject-linux-gnu/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccWgsSJO.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o hello /usr/lib/../lib64/crt1.o /usr/lib/../lib64/crti.o /home/nan/x86_64-gdcproject-linux-gnu/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/crtbegin.o -L/home/nan/x86_64-gdcproject-linux-gnu/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0 -L/home/nan/x86_64-gdcproject-linux-gnu/bin/../lib/gcc -L/lib/../lib64 -L/usr/lib/../lib64 -L/home/nan/x86_64-gdcproject-linux-gnu/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../.. /tmp/ccEygjf5.o -lgphobos2 -lm -lpthread …Run Code Online (Sandbox Code Playgroud) 来自Linux编程接口:
使用setlocale()设置语言环境有两种不同的方法.locale参数可以是一个字符串,指定系统上定义的一个语言环境(即/ usr/lib/locale下的一个子目录的名称),例如de_DE或en_US.或者,可以将语言环境指定为空字符串,这意味着应该从环境变量中获取语言环境设置:
setlocale(LC_ALL,"");
我们必须进行此调用,以便程序能够识别语言环境变量.如果省略调用,则这些环境变量对程序没有影响.
所以,按我的understaning,如果我的程序不调用setlocale明确的功能,我的程序会使用默认的locale,这是POSIX在*nix系统中,对不对?我无法搜索指定的文档.
如果我只想专注于一个模块linux,例如perf,我如何只perf从github fork 或下载模块相关文件?我尝试了以下命令:
c:\work> git clone https://github.com/torvalds/linux/tree/master/tools/perf
Cloning into 'perf'...
fatal: repository 'https://github.com/torvalds/linux/tree/master/tools/perf/' not found
Run Code Online (Sandbox Code Playgroud)
但它不能工作。
我想运行一个ubuntu容器并输入bash:
[root@localhost backup]# docker run ubuntu bash
[root@localhost backup]#
Run Code Online (Sandbox Code Playgroud)
该ubuntu容器直接退出.我怎么进入bash?
我的操作系统是Arch Linux. 当有 coredump 时,我尝试使用 gdb 来调试它:
$ coredumpctl gdb 1621
......
Storage: /var/lib/systemd/coredump/core.runTests.1014.b43166f4bba84bcba55e65ae9460beff.1621.1491901119000000000000.lz4
Message: Process 1621 (runTests) of user 1014 dumped core.
Stack trace of thread 1621:
#0 0x00007ff1c0fcfa10 n/a (n/a)
GNU gdb (GDB) 7.12.1
......
Reading symbols from /home/xiaonan/Project/privDB/build/bin/runTests...done.
BFD: Warning: /var/tmp/coredump-28KzRc is truncated: expected core file size >= 2179375104, found: 2147483648.
Run Code Online (Sandbox Code Playgroud)
我检查/var/tmp/coredump-28KzRc文件:
$ ls -alth /var/tmp/coredump-28KzRc
-rw------- 1 xiaonan xiaonan 2.0G Apr 11 17:00 /var/tmp/coredump-28KzRc
Run Code Online (Sandbox Code Playgroud)
2GLinux 上 coredump 文件的大小有限制吗?因为我认为我/var/tmp有足够的磁盘空间可以使用:
$ …Run Code Online (Sandbox Code Playgroud) 我的FreeBSD是11.0,并发现make无法处理ifdef指令。例如:
ifdef VERBOSE
Q :=
else
Q := @
endif
Run Code Online (Sandbox Code Playgroud)
该make会抱怨:
make: "/root/Project/powermon/Makefile" line 13: Need an operator
make: "/root/Project/powermon/Makefile" line 15: Need an operator
make: "/root/Project/powermon/Makefile" line 17: Need an operator
Run Code Online (Sandbox Code Playgroud)
我目前的解决方案正在使用gmake。那么是否有任何make端口FreeBSD支持处理ifdef?
检查以下代码:
#include <stdio.h>
#include <omp.h>
#define ARRAY_SIZE (1024)
float A[ARRAY_SIZE];
float B[ARRAY_SIZE];
float C[ARRAY_SIZE];
int main(void)
{
for (int i = 0; i < ARRAY_SIZE; i++)
{
A[i] = i * 2.3;
B[i] = i + 4.6;
}
double start = omp_get_wtime();
for (int loop = 0; loop < 1000000; loop++)
{
#pragma omp simd
for (int i = 0; i < ARRAY_SIZE; i++)
{
C[i] = A[i] * B[i];
}
}
double end = omp_get_wtime();
printf("Work consumed %f seconds\n", …Run Code Online (Sandbox Code Playgroud)