实验题目
编写一个父子协作进程,父进程创建一个子进程并控制它每隔 3 秒显示一次当前目录中的文件名列表。
实验代码
pctl.h
#include <sys/types.h>
#include <wait.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h> //进程自定义的键盘中断信号处理函数
typedef void (*sighandler_t) (int);
void sigcat()
{
printf("%d Process continue\n",getpid());
}
pctl.c
#include "pctl.h"
int main( int argc,char* argv[])
{
int t;
int pid;
int status;
int childpid;
char *args[]={"/bin/ls","-a",NULL};
signal(SIGUSR1,(sighandler_t)sigcat);
pid=fork();
if(pid<0)
{
printf("Create Process fail!\n");
}
if(pid==0)
{
while ((1))
{
pause();
childpid=fork();
if(childpid<0)
exit(EXIT_FAILURE);