Created
September 29, 2021 10:41
-
-
Save leveryd/277852e2e741eb24b0b4bb8dc0220ef2 to your computer and use it in GitHub Desktop.
测试execve是否会销毁所有线程
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <pthread.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#define NUM_OF_TASKS 1 | |
void *func() | |
{ | |
while (1) { | |
printf("%s\n", "hi"); | |
sleep(1); | |
} | |
} | |
int main(int argc, char *argv[]) | |
{ | |
pthread_t thread; | |
int rc; | |
int t; | |
int downloadtime; | |
pthread_attr_t thread_attr; | |
pthread_attr_init(&thread_attr); | |
pthread_attr_setdetachstate(&thread_attr,PTHREAD_CREATE_JOINABLE); | |
rc = pthread_create(&thread, &thread_attr, func, NULL); | |
if (rc){ | |
printf("ERROR; return code from pthread_create() is %d\n", rc); | |
exit(-1); | |
} | |
sleep(3); | |
execve("/bin/sh", 0, 0); | |
} |
Author
leveryd
commented
Sep 29, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment