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

📄 9-2.c

📁 《Linux应用开发技术详解》附书光盘中的例程。
💻 C
字号:
#include <unistd.h>	/* defines fork(), and pid_t.      */
#include <sys/wait.h>	/* defines the wait() system call. */
main() {
/* storage place for the pid of the child process, and its exit status. */
pid_t child_pid;
int child_status;

/* lets fork off a child process... */
child_pid = fork();

/* check what the fork() call actually did */
switch (child_pid) {
    case -1:	/* fork() failed */
	perror("fork");	/* print a system-defined error message */
	exit(1);
    case 0:	/* fork() succeeded, we're inside the child process */
	printf("hello world\n");
	exit(0);	/* here the CHILD process exits, not the parent. */
    default:	/* fork() succeeded, we're inside the parent process */
	wait(&child_status);	/* wait till the child process exits */
}
}

⌨️ 快捷键说明

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