diff --git a/fock/.vscode/settings.json b/fock/.vscode/settings.json new file mode 100644 index 0000000..1992e5c --- /dev/null +++ b/fock/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "unistd.h": "c" + } +} \ No newline at end of file diff --git a/fock/fock.bin b/fock/fock.bin index 6d6667a..1f31014 100755 Binary files a/fock/fock.bin and b/fock/fock.bin differ diff --git a/fock/fock.c b/fock/fock.c index b704e2a..7473e04 100644 --- a/fock/fock.c +++ b/fock/fock.c @@ -1,5 +1,53 @@ #include -int main(void){ - printf("hello\n"); +#include +#include +#include +#include +#include +#include +#include +#include + +extern char **environ; + + +int weak_process(){ + printf("get signal\n"); +} +int main(void) +{ + // 获取进程ID + printf("I am %d \n", getpid()); + printf("My parent is %d\n", getppid()); + // 打印环境变量 + // char **env = environ; + // while (*env != NULL) + // { + // printf("%s\n", *env); + // *env++; + // } + // fock创建进程 + // fock创建的子进程一般用来执行新的程序 + signal(SIGUSR1,weak_process); + pid_t pid = fork(); + if (pid == 0) + { + printf("I am child process %d\n", getpid()); + sleep(10); + _exit(0); + } + else if (pid > 0) + { + sleep(1); + kill(pid,SIGUSR1); + wait(NULL); + // printf("pit = %d\n",pid); + printf("I am parent process %d\n", getpid()); + } + else + { + printf("fork error\n"); + } + return 0; } \ No newline at end of file