~ubuntu-branches/ubuntu/saucy/strace/saucy-proposed

« back to all changes in this revision

Viewing changes to test/sfd.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2009-05-05 10:21:37 UTC
  • mfrom: (0.1.6 upstream) (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090505102137-ransgzeynrwa2yww
Tags: 4.5.18-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Add lpia as supported architecture

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
}