Guest User

Untitled

a guest
Jul 22nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 1.94 KB | None | 0 0
  1. \definecolor{middlegray}{rgb}{0.5,0.5,0.5}
  2. \definecolor{orange}{rgb}{0.8,0.3,0.3}
  3. \definecolor{yac}{rgb}{0.6,0.6,0.1}
  4. \lstset{language=C}
  5. \lstset{numbers=left, numberstyle=\tiny, numbersep=5pt, showspaces=false}
  6. \lstset{keywordstyle=\color{orange}\bfseries\emph, stringstyle=\color{yac}, commentstyle=\color{middlegray}\ttfamily}
  7. \lstset{escapechar=\§,numbers=left}
  8.  
  9. \begin{lstlisting}[language=C, firstnumber=1]
  10. #define _STRUCTURED_PROC 1
  11. #define __EXTENSIONS__
  12. #include <sys/procfs.h>
  13. #undef __EXTENSIONS__
  14. #include <sys/types.h>
  15. #include <sys/stat.h>
  16. #include <fcntl.h>
  17. #include <string.h>
  18. #include <stdlib.h>
  19. #include "errorhandler.h"
  20.  
  21. int main(int argc, char *argv[]) {
  22.    char pfad[255];
  23.    struct pstatus *status;
  24.    FILE *fh;
  25.    status = malloc(sizeof(struct pstatus));
  26.  
  27.    if (status == NULL) {
  28.        error_exit("Malloc fehler", 3);
  29.    }
  30.    if (argc != 2) {
  31.        error_exit("Es wird genau ein Parameter benoetigt.", 2);
  32.    }
  33.  
  34.    if (strlen(argv[1]) > 200) {
  35.        error_exit("Die ID ist zu gross", 4);
  36.    }
  37.  
  38.     sprintf(pfad, "/proc/%s/status", argv[1]);
  39.     fh = fopen(pfad, "rb");
  40.  
  41.     if (fh ==  NULL) {
  42.        error_exit("Fopen fehler", 5);
  43.    }
  44.    if (
  45.            fread(status, (size_t)1, sizeof(struct pstatus), fh)
  46.            != sizeof(struct pstatus)
  47.        ) {
  48.        error_exit("Fread fehler, Datei zu klein", 6);
  49.    }
  50.     fclose(fh);
  51.  
  52.  
  53.  
  54.     printf("Prozessid: \t %lu \n", (unsigned long)status->pr_pid);
  55.     printf("Parent Prozessid: \t %lu \n", (unsigned long)status->pr_ppid);
  56.     printf("Leichtgewichtige Prozesse: \t %d \n", (int)status->pr_nlwp);
  57.     printf("Stackwerte: \n");
  58.     printf("Heapstart: %p\n", (void *)status->pr_brkbase);
  59.     printf("Heapgroesse: %d\n", (int)status->pr_brksize);
  60.     printf("Startadresse: %p\n", (void *)status->pr_stkbase);
  61.     printf("Groeße: %d\n", (int)status->pr_stksize);
  62.  
  63.     free(status);
  64.  
  65.     return 0;
  66. }
  67.  
  68. \end{lstlisting}
Add Comment
Please, Sign In to add comment