home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / d / strace / strace-3.000 / strace-3 / strace-3.0 / test / sfd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-29  |  661 b   |  33 lines

  1. #include <fcntl.h>
  2. #include <stdio.h>
  3. main(int argc, char *argv[])
  4. {
  5.     int pid = atoi(argv[1]);
  6.     int sfd;
  7.     char sname[32];
  8.     char buf[1024];
  9.     char *s;
  10.     int i;
  11.     int signal, blocked, ignore, caught;
  12.  
  13.     sprintf(sname, "/proc/%d/stat", pid);
  14.     if ((sfd = open(sname, O_RDONLY)) == -1) {
  15.         perror(sname);
  16.         return 1;
  17.     }
  18.     i = read(sfd, buf, 1024);
  19.     buf[i] = '\0';
  20.     for (i = 0, s = buf; i < 30; i++) {
  21.         while (*++s != ' ') {
  22.             if (!*s)
  23.                 break;
  24.         }
  25.     }
  26.     if (sscanf(s, "%d%d%d%d", &signal, &blocked, &ignore, &caught) != 4) {
  27.         fprintf(stderr, "/proc/pid/stat format error\n");
  28.         return 1;
  29.     } 
  30.     printf("%8x %8x %8x %8x\n", signal, blocked, ignore, caught);
  31.     return 1;
  32. }
  33.