naufalphew

protov2

Apr 16th, 2021
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <sys/stat.h>
  4. #include <wait.h>
  5. #include <sys/types.h>
  6. #include <fcntl.h>
  7. #include <time.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <errno.h>
  11. #include <syslog.h>
  12. #define Size 50
  13.  
  14. int main() {
  15.   pid_t pid, sid;        // Variabel untuk menyimpan PID
  16.  
  17.   pid = fork();     // Menyimpan PID dari Child Process
  18.  
  19.   /* Keluar saat fork gagal
  20.   * (nilai variabel pid < 0) */
  21.   if (pid < 0) {
  22.     exit(EXIT_FAILURE);
  23.   }
  24.  
  25.   /* Keluar saat fork berhasil
  26.   * (nilai variabel pid adalah PID dari child process) */
  27.   if (pid > 0) {
  28.     exit(EXIT_SUCCESS);
  29.   }
  30.  
  31.   umask(0);
  32.  
  33.   sid = setsid();
  34.   if (sid < 0) {
  35.     exit(EXIT_FAILURE);
  36.   }
  37.  
  38.   if ((chdir("/home/zenryuu/Documents/SoalShift2/no1")) < 0) {
  39.     exit(EXIT_FAILURE);
  40.   }
  41.  
  42.   close(STDIN_FILENO);
  43.   close(STDOUT_FILENO);
  44.   close(STDERR_FILENO);
  45.  
  46.   while (1) {
  47.     // Tulis program kalian di sini
  48.      time_t t ;
  49.     struct tm *tmp ;
  50.     char MY_TIME[Size];
  51.     time( &t );
  52.      
  53.     //localtime() uses the time pointed by t ,
  54.     // to fill a tm structure with the
  55.     // values that represent the
  56.     // corresponding local time.
  57.      
  58.     tmp = localtime( &t );
  59.      
  60.     // using strftime to display time
  61.     strftime(MY_TIME, sizeof(MY_TIME), "%d/%m - %H:%M", tmp);
  62.     char first[20] = "09/04 - 16:22";
  63.     char first[20] = "09/04 - 22:22";
  64.  
  65.     pid_t pid1, pid2,pid3,pid4,pid5,pid6,pid7,pid8,pid9,pid10,pid11,pid12;
  66.     int status, status2,status3;
  67.     pid1 = fork();
  68.   if(pid1 == 0){
  69.    
  70.     char *argv[] = {"mkdir", "Musyik", NULL};
  71.     execv("/bin/mkdir", argv);
  72.   }
  73.   else{
  74.         pid2 = fork();
  75.         if(pid2 == 0){
  76.            
  77.             char *argv[] = {"mkdir", "Fylm", NULL};
  78.             execv("/bin/mkdir", argv);
  79.         }
  80.         else {
  81.         pid3 = fork();
  82.         if(pid3 == 0){
  83.            
  84.             char *argv[] = {"mkdir", "Pyoto", NULL};
  85.             execv("/bin/mkdir", argv);
  86.         }
  87.         else{
  88.         while ((wait(&status)) > 0);
  89.         pid4 = fork();
  90.         if(pid4 == 0){
  91.            
  92.             char *argv[] = {"wget","--no-check-certificate","-O", "Musik_for_Stevany.zip","https://drive.google.com/uc?id=1ZG8nRBRPquhYXq_sISdsVcXx5VdEgi-J&export=download", NULL};
  93.             execv("/bin/wget", argv);
  94.             sleep(5);
  95.         }
  96.         else {
  97.         while ((wait(&status2)) > 0);
  98.         pid5 = fork();
  99.         if(pid5 == 0){
  100.             char *argv[] = {"unzip", "Musik_for_Stevany.zip", NULL};
  101.             execv("/bin/unzip", argv);
  102.             sleep(5);
  103.         }
  104.         else {
  105.         while ((wait(&status3)) > 0);
  106.         pid6 = fork();
  107.         if(pid6 == 0){
  108.             char *argv[] = {"wget","--no-check-certificate","-O", "Foto_for_Stevany.zip","https://drive.google.com/uc?id=1FsrAzb9B5ixooGUs0dGiBr-rC7TS9wTD&export=download", NULL};
  109.             execv("/bin/wget", argv);
  110.             sleep(5);
  111.         }
  112.         else{
  113.             while ((wait(&status4)) > 0);
  114.             pid7 = fork();
  115.             if(pid7 == 0){
  116.                 char *argv[] = {"unzip", "Foto_for_Stevany.zip", NULL};
  117.                 execv("/bin/unzip", argv);
  118.                 sleep(5);
  119.             }
  120.             else{
  121.                 while ((wait(&status5)) > 0);
  122.                 pid8 = fork();
  123.                 if(pid8 == 0){
  124.                     char *argv[] = {"wget","--no-check-certificate","-O", "Film_for_Stevany.zip","https://drive.google.com/uc?id=1ktjGgDkL0nNpY-vT7rT7O6ZI47Ke9xcp&export=download", NULL};
  125.                     execv("/bin/wget", argv);
  126.                     sleep(5);
  127.                 }
  128.                 else{
  129.                     while ((wait(&status6)) > 0);
  130.                     pid9 = fork();
  131.                     if(pid9 == 0){
  132.                         char *argv[] = {"unzip", "Film_for_Stevany.zip", NULL};
  133.                         execv("/bin/unzip", argv);
  134.                         sleep(5);
  135.                     }
  136.                     else{
  137.                         while ((wait(&status3) > 0));
  138.                         pid10 = fork();
  139.                         if(pid10 == 0){
  140.                             char *argv[] = {"mv", "MUSIK","Musyik", NULL};
  141.                             execv("/bin/mv", argv);
  142.                         }
  143.                         else {
  144.                             pid11 = fork();
  145.                             if(pid11 == 0){
  146.                                 char *argv[] = {"mv", "FILM","Fylm", NULL};
  147.                                 execv("/bin/mv", argv);
  148.                             }
  149.                             else{
  150.                                 pid12 = fork();
  151.                                 if(pid12 == 0){
  152.                                     char *argv[] = {"mv", "FOTO","Pyoto", NULL};
  153.                                     execv("/bin/mv", argv);
  154.                                 }
  155.                             }
  156.                         }
  157.                     }
  158.                 }
  159.             }
  160.         }
  161.         }
  162.         }
  163.         }
  164.         }
  165.   }
  166.     sleep(600);
  167.   }//ini while
  168.  
  169. }//ini main
Advertisement
Add Comment
Please, Sign In to add comment