IOday5作业

1.僵尸进程

#include 
#include 
#include 
#include 
#include 
int main(int argc, const char *argv[])
{
    pid_t cpid = fork();
    if (cpid > 0)
    {
        while (1)
        {
            printf("this is parent\n");
            sleep(1);
        }
    }
    else if (0 == cpid)
    {
    }
    else
    {
        perror("fork");
        return -1; 
    }
    return 0;
}

 2.孤儿进程

#include 
#include
#include
#include
#include
int main(int argc, const char *argv[])
{
   pid_t cpid=fork();
   if(cpid>0)
   {
	   printf("this is parent %d %d\n",getpid(),cpid);
   }
   else if(0==cpid)
   {
   	while(1){
	   printf("this is child %d %d %d\n",getppid(),getpid(),__LINE__);
	   sleep(1);
	}
   }
   else 
   {
   	perror("fork");
	return -1;
   }
    return 0;
}

 3.守护进程

#include 
#include 
#include 
#include
#include
#include
#include
int main(int argc, const char *argv[])
{
	pid_t cpid=fork();
	if(0==cpid)
	{
		setsid();
		chdir("/");
		for(int i=0;i

 

你可能感兴趣的:(数据结构,算法,c语言)