2012-02-27 Pedro Alves <palves@redhat.com>
[deliverable/binutils-gdb.git] / gdb / common / linux-procfs.c
index 421f36edb46a671f1fa8152d37a6963078db8c4a..165383e8755813948bd74765c4cc8b3458097e3b 100644 (file)
@@ -53,3 +53,34 @@ linux_proc_get_tgid (int lwpid)
 
   return tgid;
 }
+
+/* Detect `T (stopped)' in `/proc/PID/status'.
+   Other states including `T (tracing stop)' are reported as false.  */
+
+int
+linux_proc_pid_is_stopped (pid_t pid)
+{
+  FILE *status_file;
+  char buf[100];
+  int retval = 0;
+
+  snprintf (buf, sizeof (buf), "/proc/%d/status", (int) pid);
+  status_file = fopen (buf, "r");
+  if (status_file != NULL)
+    {
+      int have_state = 0;
+
+      while (fgets (buf, sizeof (buf), status_file))
+       {
+         if (strncmp (buf, "State:", 6) == 0)
+           {
+             have_state = 1;
+             break;
+           }
+       }
+      if (have_state && strstr (buf, "T (stopped)") != NULL)
+       retval = 1;
+      fclose (status_file);
+    }
+  return retval;
+}
This page took 0.032488 seconds and 4 git commands to generate.