
linux二进制可执行文件是无法得转换为代码的,所以修改不了代码,只能找源码去改,改完了重新交叉编译再写进开发板上。
2)
使用linux多线程问题,A中满足条件创建线程B,线程B中满足条件创建线程C,如果你线程A和B没有退出,A和B都会继续执行
实例程序如下:main中十秒后创建线程A ,A中10秒后创建B,B线程十秒后创建线程C,每个线程中都会有打印信息,当出现pthread A pthread B pthread C同时出现时,证明三个线程同时存活
此程序编译时需加-phread参数,例如:cc pthread_join.c -pthread
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <pthread.h>
void * A()//线程函数声明
void * B()
void * C()
void * A()
{
pthread_t b
int i = 0
while(i <50)
{
if (++i == 10)
pthread_create(&b, NULL, (void *)B, NULL )//创建线程B
sleep(1)
printf("pthread A\n")
}
pthread_join(b, NULL)
return 0
}
void * B()
{
pthread_t c
int i = 0
while(i <30)
{
if (++i == 10)
pthread_create(&c, NULL, (void *)C, NULL )//创建线程C
printf("pthread B\n")
sleep(1)
}
pthread_join(c, NULL)
return 0
}
void *C()
{
int i = 0
while(i <10)//C线程执行10秒后退出,资源在B线程中pthread_join函数回收
{
printf("pthread C\n")
sleep(1)
i++
}
return 0
}
int main()
{
pthread_t a
int i = 0
while(i <100)
{
if (++i == 10)
pthread_create(&a, NULL, (void *)A, NULL )//创建线程A
printf("i = %d\n", i )
sleep(1)
}
pthread_join(a, NULL)
return 0
}
以上是多线程程序的例子
但是,如果你想一个程序调用另一个程序时,你可以这样做:
比如你有三个可执行程序a.out b.out c.out
运行a.out当符合某个程序时使用system("./b.out")调用程序b.out,在b.out程序中以同样的方法调用程序c.out。但此时已经不是多线程了,而是三个不同的进程,进程a.out b.out 和c.out
也可以在上面的程序中十秒的时候创建子进程后,在子进程中以system("./b.out")来运行程序b.out
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)