forked from p7px8vou9/system_call_expand
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
929 B
49 lines
929 B
/*
|
|
* 测试成功时输出:
|
|
* "clone success."
|
|
* 测试失败时输出:
|
|
* "clone error."
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <assert.h>
|
|
#include <signal.h>
|
|
#include <linux/sched.h>
|
|
|
|
size_t stack[1024] = {0};
|
|
static int child_pid;
|
|
int g_shared = 0;
|
|
|
|
static int child_func(void){
|
|
g_shared = 1;
|
|
printf(" Child says hello.\n");
|
|
return 0;
|
|
}
|
|
|
|
void test_clone(void){
|
|
int wstatus;
|
|
child_pid = clone(child_func, stack+1024, SIGCHLD|CLONE_VM);
|
|
assert(child_pid != -1);
|
|
|
|
if (child_pid == 0){
|
|
exit(0);
|
|
}
|
|
printf("child pid: %d\n", child_pid);
|
|
|
|
int ret = wait(&wstatus);
|
|
if(ret == child_pid) {
|
|
if (g_shared == 1) {
|
|
printf("clone success.\n");
|
|
}
|
|
}
|
|
else {
|
|
printf("clone error.\n");
|
|
}
|
|
}
|
|
|
|
int main(void){
|
|
test_clone();
|
|
return 0;
|
|
}
|