Tag: linux

如何使用clone()使父进程和子进程同时运行?

我是linux的新手。 我想同时制作子进程和父进程。 但我失败了。 这是我的代码。 有谁能够帮我? #define _GNU_SOURCE #include #include #include #include #include #define FIBER_STACK 8192 void * stack; int do_something(){ int a = 0; while (a<10){ printf("pid : %d, a = %d\n", getpid(), a++); } exit(1); } int main() { void * stack; stack = malloc(FIBER_STACK); if(!stack) { printf("The stack failed\n"); exit(0); } int a […]

为什么popen不与pog123沟通?

我正在为我的覆盆子pi写一个媒体服务器。 我能够创建一个程序,使用popen通过遥控器控制omxplayer。 我现在想控制mpg123音乐。 我使用与popen在omxplayer程序中工作的相同代码并将其应用于mpg123,但它无法正常工作。 它启动,但不会确认发送给它的任何输入。 我不知道为什么一个会工作而另一个不会。 这是我的代码: void play_music (char *list, int random) { FILE *pp; char c; char command[501]; struct stat buf; if(access(list, R_OK) == -1) { fprintf(stderr, “%s: play_music: access failed (%s) (%s)\n”, program_name, strerror(errno), list); exit(EXIT_FAILURE); } if(stat(list, &buf) == -1) { fprintf(stderr, “%s: play_music: stat failed (%s) (%s)\n”, program_name, strerror(errno), list); […]

在XeonPhi上使用AVX内联汇编的矢量和

我是新手使用XeonPhi Intel协处理器。 我想使用AVX 512位指令为简单的矢量和编写代码。 我使用k1om-mpss-linux-gcc作为编译器,并希望编写内联汇编。 这是我的代码: #include #include #include #include #include #include void* aligned_malloc(size_t size, size_t alignment) { uintptr_t r = (uintptr_t)malloc(size + –alignment + sizeof(uintptr_t)); uintptr_t t = r + sizeof(uintptr_t); uintptr_t o =(t + alignment) & ~(uintptr_t)alignment; if (!r) return NULL; ((uintptr_t*)o)[-1] = r; return (void*)o; } int main(int argc, char* argv[]) { […]

makefile中的gdb和valgrind

我有一个非常基本的问题。 我确实在这里环顾四周http://www.cs.cmu.edu/~gilpin/tutorial/但仍然怀疑.. 考虑以下makefile(在之前的问题中也给出了它) all: clients.so simulator backup LD_PRELOAD=/home/Juggler/client/clients.so ./simulator backup: backup.c libclient.a gcc backup.c -o backup -L /home/Juggler/client -L. -lclient -ldl simulator: simulator.c libclient.a gcc -g simulator.c -o simulator -L /home/Juggler/client -L. -lclient -ldl -pthread libclient.a: libclient.o client.o ar rcs libclient.a libclient.o client.o libclient.o:libclient.c gcc -c libclient.c -o libclient.o -pthread clients.so: client.o client_invoke.o ld -shared […]

包装abort()系统调用时出现奇怪的行为

我需要编写单一测试来包装abort()系统调用。 这是一段代码: #include #include #include extern void __real_abort(void); extern void * __real_malloc(int c); extern void __real_free(void *); void __wrap_abort(void) { printf(“=== Abort called !=== \n”); } void * __wrap_malloc(int s) { void *p = __real_malloc(s); printf(“allocated %d bytes @%p\n”,s, (void *)p); return p; } void __wrap_free(void *p) { printf(“freeing @%p\n”,(void *)p); return __real_free((void *)p); } […]

gcc链接订单问题

我目前在使用以下行编译时遇到问题: gcc test.c -I/usr/include -L/lib -lipc -lpcd -lrt -o /home/examples/bin/test 我被建议使用start-group和end-group对它们进行分组。 我无法获得正确的语法。 我想我需要这个部分,但整条线是什么样的? -Wl,–start-group -lipc -lpcd -lrt -Wl,–end-group

我如何正确链接libssh?

我正试图在我的代码中包含一个lib(libssh),但没有任何作用……此时我不确定该怎么做,因为搜索引擎中没有结果出现我正在接收的错误。 我在这里下载了libssh: https : //github.com/substack/libssh 我安装了这些: yum install cmake zlib-devel libpng-devel openssl-devel -y; 创建了一个“build”目录作为libssh的父目录,移动到那里,键入: cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug .. make [root@ build]# cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug LD_DEBUG=all .. — Could NOT find NaCl (missing: NACL_LIBRARIES NACL_INCLUDE_DIRS) — ******************************************** — ********** libssh build options : ********** — zlib support: ON — libgcrypt support: OFF — libnacl support: OFF […]

线程具有相同的ID

我学习线程。 我已经读过该线程在一个函数之外终止(它作为参数传递给pthread_create函数)。 所以我在循环中创建线程,它们被执行,之后它们被终止。 (对不起一些长代码) 但是当我调用函数pthread_create时,新线程获得相同的ID。 为什么? struct data { FILE *f; }; void *read_line_of_file(void *gdata) { pthread_mutex_lock(&g_count_mutex); // only one thread can work with file, //doing so we block other threads from accessing it data *ldata = (data *) gdata; char line[80]; int ret_val =fscanf(ldata->f,”%s”,line); pthread_mutex_unlock(&g_count_mutex); // allow other threads to access it if (ret_val […]

Makefile提供重复错误C.

我创建了一个makefile来同时运行9个程序。 9个程序的名称是init_aim.c,register.c,sort.c,schedule.c,add.c,class_schedule.c,class_list.c,grade.c和report.c。 在我实现代码的每个文件中: #include “aim.h” int main(){ return 0; } 我还有一个带代码的头文件 #ifndef AIM_H #define AIM_H #endif 我唯一的目标是让我的makefile正常工作。 并且还添加“all:”规则。 我当前的makefile看起来像这样。 AIS: init_aim.o register.o sort.o schedule.o add.o class_schedule.o class_list.o grade.o report.o gcc -Wall -ansi -pedantic init_aim.o register.o sort.o schedule.o add.o class_schedule.o class_list.o grade.o report.o -o AIS init_aim.o: init_aim.c aim.h gcc -Wall -ansi -pedantic -c init_aim.c -o init_aim.o […]

通过C程序获取Linux中的网络接口类型

如何从Linux中的C程序获取网络接口的类型名称? 我尝试使用getifaddr访问网络接口,我得到了我需要的一切,除了它的类型名称。 有什么想法可以做到吗? 我还是Linux新手,所以对任何变通办法或示例代码的任何评论都会受到赞赏。 编辑 详细说明问题。 基本上,在做ifconfig我可以得到这样的东西: eth0链接封装:以太网HWaddr 00:0C:29:40:93:9C inet addr:192.168.154.102 Bcast:192.168.154.255 Mask:255.255.255.0 inet6 addr:fe80 :: 20c:29ff:fe40:939c / 64范围:链接 UP BROADCAST RUNNING MULTICAST MTU:1500公制:1 RX数据包:14785错误:0丢弃:0超限:0帧:0 TX数据包:429错误:0丢弃:0溢出:0载波:0 碰撞:0 txqueuelen:1000 RX字节:961439(938.9 KiB)TX字节:71866(70.1 KiB) 中断:67基地址:0x2000 以下是我所理解的eth0是接口名称。 虽然可以有多个网络接口(eth0,eth1,eth2)和几个虚拟接口(tap0,tap1等)和无线接口,但它们都是以太网接口。 环回也一样,作为接口名称,其接口是Local Loopback。 所以问题是,我怎样才能使用C程序打印eth0,tap0,wlan0属于以太网类型,并且lo – >到本地环回类型,当我事先不知道使用什么接口和多少他们在机器里。 希望我能正确解释一下。