IOday5

IOday5_第1张图片

1.

  1 #include 
  2 #include 
  3 #include 
  4 #include 
  5 #include 
  6 #include 
  7 #include 
  8 #include 
  9 int main(int argc, const char *argv[])
 10 {
 11     pid_t cpid=fork();
 12 
 13     if(0==cpid)
 14     {
 15         pid_t sid=setsid();
 16         printf("新会话%d\n",sid);
 17         chdir("/");
 18         umask(0);
 19         for(int i=0;i

 2.、

  1 #include 
  2 #include 
  3 #include 
  4 #include 
  5 #include 
  6 #include 
  7 int main(int argc, const char *argv[])
  8 {
  9 
 10     time_t t;
 11     struct tm* n=NULL;
 12     pid_t flag;
 13     pid_t p=fork();
 14     if(p==0)
 15     {
 16         while(1)
 17         {
 18         printf("please give a commoned\n");
 19         char c[20];
 20         scanf("%s",c);
 21         if(strcmp(c,"quit")==0)
 22             putchar(10);                                                    
 23             sleep(1);
 24             putchar(10);
 25             exit(0);
 26         }
 27     }
 28     
 29     if(p>0)
 30     {   
 31         while(1)
 32         {   
 33             t=time(NULL);
 34             n=localtime(&t);
 35             printf("%d-%02d-%02d  %02d:%02d:%02d\r",\
 36                     n->tm_year+1900,n->tm_mon+1,n->tm_mday,\
 37                     n->tm_hour,n->tm_min,n->tm_sec);
 38             fflush(stdout);
 39             sleep(1);
 40             flag=waitpid(p,NULL,WNOHANG);
 41             if(flag>0)
 42             {
 43                 return 0;
 44             }
 45         }
 46     }
 47     else
 48         printf("error");
 49     return 0;
 50 }            

3.xmind

IOday5_第2张图片

 

你可能感兴趣的:(c语言,linux)