userstack 多进程
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
# FROM debian
|
||||
FROM rockylinux:8.8.20230518
|
||||
|
||||
# copy 并安装 /root/diagnose-tools/rpmbuild/RPMS/x86_64/diagnose-tools-2.1-release.el8.x86_64.rpm
|
||||
# 拷贝 RPM 文件到 Docker 镜像中
|
||||
# COPY /diagnose-tools-2.1-release.el8.x86_64.rpm
|
||||
|
||||
# 安装 RPM 文件
|
||||
# RUN dnf install -y /diagnose-tools-2.1-release.el8.x86_64.rpm && \
|
||||
# rm -f /diagnose-tools-2.1-release.el8.x86_64.rpm
|
||||
@@ -11,10 +15,5 @@ COPY build/userstack /userstack
|
||||
# 使拷贝进去的 userstack 文件可执行
|
||||
RUN ls /
|
||||
RUN chmod +x /userstack
|
||||
|
||||
# copy 并安装 /root/diagnose-tools/rpmbuild/RPMS/x86_64/diagnose-tools-2.1-release.el8.x86_64.rpm
|
||||
# 拷贝 RPM 文件到 Docker 镜像中
|
||||
COPY /diagnose-tools-2.1-release.el8.x86_64.rpm /
|
||||
|
||||
# 设置容器启动时运行的命令
|
||||
ENTRYPOINT ["/userstack"]
|
||||
2
Makefile
2
Makefile
@@ -23,7 +23,7 @@ $(OUTPUT_DIR)/%: $(TDIR)/%.c
|
||||
$(OUTPUT_DIR)/$(USTACK): $(TDIR)/$(USTACK).c
|
||||
mkdir -p $(@D)
|
||||
# $(CC) -g $(CFLAGS) -o $@ $< -lunwind -lunwind-x86_64
|
||||
$(CC) -g -O2 $(CFLAGS) -o $@ $<
|
||||
$(CC) -g -O2 $(CFLAGS) -o $@ $< -lpthread
|
||||
|
||||
# $(SPID): $(TDIR)/stack-pid.c
|
||||
# mkdir -p $(OUTPUT_DIR)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#include <stdio.h>
|
||||
// #include <libunwind.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
|
||||
void customFunction1(int n);
|
||||
// void customFunction1(int n);
|
||||
void *customFunction1(void *n);
|
||||
void customFunction2(int n);
|
||||
void customFunction3(int n);
|
||||
|
||||
@@ -33,34 +35,61 @@ void customFunction3(int n);
|
||||
// }
|
||||
// }
|
||||
|
||||
void customFunction1(int n) {
|
||||
if(n <= 0) {
|
||||
void *customFunction1(void *n) {
|
||||
int num = *((int *)n);
|
||||
if(num <= 0) {
|
||||
printf("End of recursion\n");
|
||||
// output backtrace
|
||||
printf("pid: %d\n", getpid());
|
||||
// backtrace();
|
||||
while (1) {
|
||||
sleep(1);
|
||||
} // never return, keep stack
|
||||
return;
|
||||
return NULL;
|
||||
} else {
|
||||
printf("Calling customFunction2\n");
|
||||
customFunction2(n-1);
|
||||
customFunction2(num-1);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void customFunction2(int n) {
|
||||
printf("Calling customFunction3\n");
|
||||
customFunction3(n);
|
||||
printf("Calling customFunction2\n");
|
||||
if(n <= 0) {
|
||||
printf("End of recursion\n");
|
||||
printf("pid: %d\n", getpid());
|
||||
while (1) {
|
||||
sleep(1);
|
||||
} // never return, keep stack
|
||||
return NULL;
|
||||
}
|
||||
customFunction3(n-1);
|
||||
}
|
||||
|
||||
void customFunction3(int n) {
|
||||
printf("Calling customFunction1\n");
|
||||
customFunction1(n);
|
||||
printf("Calling customFunction3\n");
|
||||
if(n <= 0) {
|
||||
printf("End of recursion\n");
|
||||
printf("pid: %d\n", getpid());
|
||||
while (1) {
|
||||
sleep(1);
|
||||
} // never return, keep stack
|
||||
return NULL;
|
||||
}
|
||||
customFunction2(n-1);
|
||||
}
|
||||
|
||||
int main() {
|
||||
customFunction1(10);
|
||||
int num1 = 4;
|
||||
int num2 = 5;
|
||||
int num3 = 6;
|
||||
|
||||
pthread_t thread_id1, thread_id2, thread_id3;
|
||||
|
||||
pthread_create(&thread_id1, NULL, customFunction1, &num1);
|
||||
pthread_create(&thread_id2, NULL, customFunction1, &num2);
|
||||
pthread_create(&thread_id3, NULL, customFunction1, &num3);
|
||||
|
||||
pthread_join(thread_id1, NULL);
|
||||
pthread_join(thread_id2, NULL);
|
||||
pthread_join(thread_id3, NULL);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user