main_simple.c: added for better readability
parent
9712cc188f
commit
b6b01eb4d8
@ -1,3 +1,5 @@
|
|||||||
main: main.c
|
main: main.c
|
||||||
gcc -Wall -Wextra -pedantic -o main main.c -pthread
|
gcc -Wall -Wextra -pedantic -o main main.c -pthread
|
||||||
|
main_simple: main_simple.c
|
||||||
|
gcc -Wall -Wextra -pedantic -o main_simple main_simple.c -pthread
|
||||||
|
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <sched.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define STACK_SIZE (1024 * 1024)
|
||||||
|
|
||||||
|
int child(void* buf){
|
||||||
|
printf("print buf (addr=%p): %s\n",buf,(char *) buf);
|
||||||
|
sleep(2);
|
||||||
|
printf("print buf (addr=%p): %s\n",buf, (char *)buf);
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
char * stack = malloc(STACK_SIZE * sizeof(char));
|
||||||
|
char * buf = malloc(256 * sizeof(char));
|
||||||
|
snprintf(buf,256,"inital");
|
||||||
|
clone(child, stack + STACK_SIZE, SIGCHLD | CLONE_THREAD | CLONE_SIGHAND | CLONE_VM, buf);
|
||||||
|
sleep(1);
|
||||||
|
snprintf(buf,256,"changed");
|
||||||
|
sleep(2);
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
Loading…
Reference in New Issue