Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. #include <stdio.h> /* perror printf */
  2. #include <stdlib.h> /* free exit */
  3. #include <fcntl.h> /* open */
  4. #include <unistd.h> /* chdir fchdir */
  5. #include <sys/stat.h> /* stat */
  6. #include <dirent.h> /* DIR */
  7. #include <sys/statvfs.h> /* statvfs */
  8. #include <string.h> /* strlen strcat strcpy */
  9. #include <stdarg.h> /* for printf ovveride */
  10. #include <sys/wait.h>
  11. #include <sys/mman.h>
  12. #include <dlfcn.h>
  13. /*VARIABLES*/
  14. /* -------------VARIABLES*/
  15.  
  16.  
  17. int main ( int argc, char *argv[] )
  18. {
  19. int i;
  20. int st;
  21. void *dl;
  22. void *dl2;
  23. for(i = 1; i < argc; i++)
  24. {
  25. pid_t child_a, child_b, rv;
  26.  
  27. child_a = fork();
  28. if (child_a == 0)
  29. {
  30. dl = dlopen(argv[i], RTLD_LAZY | RTLD_LOCAL );
  31. if( dl == NULL ){
  32. puts( dlerror() );
  33. exit(1);
  34. }
  35. printf("PID: %lu PPID: %lu - vaikas: %s\n", getpid(), getppid(), argv[i]);
  36. rv = wait( &st );
  37. }
  38. else
  39. {
  40. child_b = fork();
  41. if (child_b == 0)
  42. {
  43. dl2 = dlopen(argv[i], RTLD_LAZY | RTLD_LOCAL );
  44. if( dl2 == NULL ){
  45. puts( dlerror() );
  46. exit(1);
  47. }
  48. printf("PID: %lu PPID: %lu - vaikas: %s\n", getpid(), getppid(), argv[i]);
  49. rv = wait( &st );
  50. }
  51. else
  52. {
  53. /*printf("Parent PID = %ld\n", (long)getpid());*/
  54. printf("PID: %lu - tevo procesas\n", getpid());
  55. }
  56. }
  57. }
  58. return 1;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement