⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test3.c

📁 这个是学习嵌入式开发的重要例子
💻 C
字号:
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <signal.h>#include <string.h>#include <errno.h>void signal_handler(int s);void parent_process_main();void child_process_main();int main(int argc, char **argv){  signal(SIGINT, signal_handler);  pid_t pid;  //pid_t fork(void);  if ((pid = fork()) < 0)  {    fprintf(stderr, "fork() failed: %s\n", strerror(errno));    exit(1);  }  else if (pid == 0)  {    fprintf(stdout, "I'm child process, my pid is %d, my parent pid is %d\n", getpid(), getppid());    child_process_main();    exit(0);  }  fprintf(stdout, "I'm parent process, my pid is %d, new created child pid is %d\n", getpid(), pid);  parent_process_main();  return 0;}void signal_handler(int s){  fprintf(stdout, "[%d]Catched %d signal.\n", getpid(), s);}void parent_process_main(){  for (;;)  {  }}void child_process_main(){  // pid_t setsid(void);  setsid();  for (;;)  {  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -