1、编写一段程序实现以下功能:
a) 使用系统调用fork()创建两个子进程
b) 各个子进程显示和输出一些提示信息和自己的进程标识符。
c) 父进程显示自己的进程ID和一些提示信息,然后调用waitpid()等待多个子进程结束,并在子进程结束后显示输出提示信息表示程序结束。
2、
创建两个子进程的代码如下:
#include <unistd.h>
#include <stdarg.h>
#include <time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
int tprintf (const char *fnt,...);
int main(void)
{
pid_tpid1,pid2;
inti;
printf("Hellofrom parent process,pid is %d.\n",getpid());
pid1=fork();
if(pid1==0)
{
sleep(1);
for(i=0;i<3;i++)
{
tprintf("Hellofrom child NO.1 process %d. %d times\n",getpid(),i+1);
sleep(1);
}
return0;
}