Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include "proto.h"
  2. #include <sys/types.h>
  3. #include <stdlib.h>
  4. /*
  5. mproc[NR_PROCS]
  6. char mp_exitstatus - status procesu ktory istnieje
  7. char mp_sigstatus - status # dla zabitych procesow
  8. pid_t mp_pid - id procesu
  9. uid_t mp_realuid - uid procesu
  10. int mp_parent - id rodzica
  11. */
  12.  
  13. bool acompare(mproc lhs, mproc rhs) { return lhs.mp_pid < rhs.mp_pid; }
  14.  
  15. int pstree(pid_t pid, int uid);
  16. int pstree2(pid_t pid, int uid, int depth);
  17.  
  18. int pstree(pid_t pid, int uid){
  19. qsort(mproc, mproc+NR_PROCS, acompare);
  20. int i = 0;
  21. for (i = 0; i < NR_PROCS; ++i){
  22. if (mproc[i].mp_pid == pid) break;
  23. }
  24. pstree2(pid,uid,0,i);
  25. }
  26.  
  27. int pstree2(pid_t pid, int uid, int depth, int index){
  28. if ((int)mproc[index].mp_realuid != uid) return 0;
  29. if (mproc[pid].mp_flags & IN_USE != IN_USE) return 0;
  30.  
  31. for (int i = 0; i < depth*3; ++i){
  32. printf("-");
  33. }
  34. printf("%jd\n", (intmax_t) pid);
  35. for (int i = index + 1; i < NR_PROCS; ++i){
  36. if (mproc[i].mp_parent == (int) pid){
  37. pstree2(i, uid, depth+1, i);
  38. }
  39. }
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement