📄 fork1.c
字号:
/**************// name : fork1.c// author : pyy// date : 2007-11-22***************/#include<unistd.h>#include<stdio.h>#include<stdlib.h>#include<string.h>int main(){ pid_t child=2; int ans; char str0[240],str1[60],str2[60],str3[60],str4[60]; printf("是否要执行复制进程? (1 yes 2 no):"); scanf("%d",&ans); if(ans == 1) { child = fork(); //copy process if(child == -1) { perror("fork error\n"); exit(1);} } strcpy(str1,"one :what a beautiful view!\n"); strcpy(str2,"two : Three buildings are worth seeing.\n"); strcpy(str3,"three: I'd like to look around the city.\n"); strcpy(str4,"four: Would you recommend some famous \n"); strcpy(str0,""); /* child process*/ if(child == 0) { puts(" child process.....:"); printf("\t child pid = %d\n",getpid()); printf("\t child ppid = %d\n",getppid()); strcat(str0,str1); strcat(str0,str2); printf("%s",str0); printf(" the length of string is %d\n ",strlen(str0)); exit(0); } else { puts(" father process.....:"); printf("\t father pid = %d\n",getpid()); printf("\t father ppid = %d\n",getppid()); strcat(str0,str3); strcat(str0,str4); printf("%s",str0); printf(" the length of string is %d\n ",strlen(str0)); exit(0); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -