1 /* Linux-specific PROCFS manipulation routines. 2 Copyright (C) 2009-2012 Free Software Foundation, Inc. 3 4 This file is part of GDB. 5 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. 10 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. 15 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/>. */ 18 19 #ifdef GDBSERVER 20 #include "server.h" 21 #else 22 #include "defs.h" 23 #include "gdb_string.h" 24 #endif 25 26 #include "linux-procfs.h" 27 28 /* Return the TGID of LWPID from /proc/pid/status. Returns -1 if not 29 found. */ 30 31 int 32 linux_proc_get_tgid (int lwpid) 33 { 34 FILE *status_file; 35 char buf[100]; 36 int tgid = -1; 37 38 snprintf (buf, sizeof (buf), "/proc/%d/status", (int) lwpid); 39 status_file = fopen (buf, "r"); 40 if (status_file != NULL) 41 { 42 while (fgets (buf, sizeof (buf), status_file)) 43 { 44 if (strncmp (buf, "Tgid:", 5) == 0) 45 { 46 tgid = strtoul (buf + strlen ("Tgid:"), NULL, 10); 47 break; 48 } 49 } 50 51 fclose (status_file); 52 } 53 54 return tgid; 55 } 56