Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \definecolor{middlegray}{rgb}{0.5,0.5,0.5}
- \definecolor{orange}{rgb}{0.8,0.3,0.3}
- \definecolor{yac}{rgb}{0.6,0.6,0.1}
- \lstset{language=C}
- \lstset{numbers=left, numberstyle=\tiny, numbersep=5pt, showspaces=false}
- \lstset{keywordstyle=\color{orange}\bfseries\emph, stringstyle=\color{yac}, commentstyle=\color{middlegray}\ttfamily}
- \lstset{escapechar=\§,numbers=left}
- \begin{lstlisting}[language=C, firstnumber=1]
- #define _STRUCTURED_PROC 1
- #define __EXTENSIONS__
- #include <sys/procfs.h>
- #undef __EXTENSIONS__
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <string.h>
- #include <stdlib.h>
- #include "errorhandler.h"
- int main(int argc, char *argv[]) {
- char pfad[255];
- struct pstatus *status;
- FILE *fh;
- status = malloc(sizeof(struct pstatus));
- if (status == NULL) {
- error_exit("Malloc fehler", 3);
- }
- if (argc != 2) {
- error_exit("Es wird genau ein Parameter benoetigt.", 2);
- }
- if (strlen(argv[1]) > 200) {
- error_exit("Die ID ist zu gross", 4);
- }
- sprintf(pfad, "/proc/%s/status", argv[1]);
- fh = fopen(pfad, "rb");
- if (fh == NULL) {
- error_exit("Fopen fehler", 5);
- }
- if (
- fread(status, (size_t)1, sizeof(struct pstatus), fh)
- != sizeof(struct pstatus)
- ) {
- error_exit("Fread fehler, Datei zu klein", 6);
- }
- fclose(fh);
- printf("Prozessid: \t %lu \n", (unsigned long)status->pr_pid);
- printf("Parent Prozessid: \t %lu \n", (unsigned long)status->pr_ppid);
- printf("Leichtgewichtige Prozesse: \t %d \n", (int)status->pr_nlwp);
- printf("Stackwerte: \n");
- printf("Heapstart: %p\n", (void *)status->pr_brkbase);
- printf("Heapgroesse: %d\n", (int)status->pr_brksize);
- printf("Startadresse: %p\n", (void *)status->pr_stkbase);
- printf("Groeße: %d\n", (int)status->pr_stksize);
- free(status);
- return 0;
- }
- \end{lstlisting}
Add Comment
Please, Sign In to add comment