1 /* Linux-specific PROCFS manipulation routines.
2 Copyright (C) 2009-2012 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "gdb_string.h"
26 #include "linux-procfs.h"
28 /* Return the TGID of LWPID from /proc/pid/status. Returns -1 if not
32 linux_proc_get_tgid (int lwpid
)
38 snprintf (buf
, sizeof (buf
), "/proc/%d/status", (int) lwpid
);
39 status_file
= fopen (buf
, "r");
40 if (status_file
!= NULL
)
42 while (fgets (buf
, sizeof (buf
), status_file
))
44 if (strncmp (buf
, "Tgid:", 5) == 0)
46 tgid
= strtoul (buf
+ strlen ("Tgid:"), NULL
, 10);
57 /* Detect `T (stopped)' in `/proc/PID/status'.
58 Other states including `T (tracing stop)' are reported as false. */
61 linux_proc_pid_is_stopped (pid_t pid
)
67 snprintf (buf
, sizeof (buf
), "/proc/%d/status", (int) pid
);
68 status_file
= fopen (buf
, "r");
69 if (status_file
!= NULL
)
73 while (fgets (buf
, sizeof (buf
), status_file
))
75 if (strncmp (buf
, "State:", 6) == 0)
81 if (have_state
&& strstr (buf
, "T (stopped)") != NULL
)
88 /* See linux-procfs.h declaration. */
91 linux_proc_pid_is_zombie (pid_t pid
)
98 xsnprintf (buffer
, sizeof (buffer
), "/proc/%d/status", (int) pid
);
99 procfile
= fopen (buffer
, "r");
100 if (procfile
== NULL
)
102 warning (_("unable to open /proc file '%s'"), buffer
);
107 while (fgets (buffer
, sizeof (buffer
), procfile
) != NULL
)
108 if (strncmp (buffer
, "State:", 6) == 0)
114 && strcmp (buffer
, "State:\tZ (zombie)\n") == 0);
This page took 0.031706 seconds and 4 git commands to generate.