Skip to content

Instantly share code, notes, and snippets.

@leveryd
Created September 29, 2021 10:41
Show Gist options
  • Save leveryd/277852e2e741eb24b0b4bb8dc0220ef2 to your computer and use it in GitHub Desktop.
Save leveryd/277852e2e741eb24b0b4bb8dc0220ef2 to your computer and use it in GitHub Desktop.
测试execve是否会销毁所有线程
#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);
}
@leveryd
Copy link
Author

leveryd commented Sep 29, 2021

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment