OLD | NEW |
1 /* | 1 /* |
2 * $Id: process_info.c 772 2010-11-03 13:51:11Z g.rodola $ | 2 * $Id: process_info.c 1142 2011-10-05 18:45:49Z g.rodola $ |
| 3 * |
| 4 * Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved. |
| 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. |
3 * | 7 * |
4 * Helper functions related to fetching process information. Used by _psutil_bsd | 8 * Helper functions related to fetching process information. Used by _psutil_bsd |
5 * module methods. | 9 * module methods. |
6 */ | 10 */ |
7 | 11 |
8 #include <Python.h> | 12 #include <Python.h> |
9 #include <assert.h> | 13 #include <assert.h> |
10 #include <errno.h> | 14 #include <errno.h> |
11 #include <stdlib.h> | 15 #include <stdlib.h> |
12 #include <stdio.h> | 16 #include <stdio.h> |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 PyList_Append(retlist, item); | 239 PyList_Append(retlist, item); |
236 Py_DECREF(item); | 240 Py_DECREF(item); |
237 pos = pos + strlen(&argstr[pos]) + 1; | 241 pos = pos + strlen(&argstr[pos]) + 1; |
238 } | 242 } |
239 } | 243 } |
240 | 244 |
241 free(argstr); | 245 free(argstr); |
242 return retlist; | 246 return retlist; |
243 } | 247 } |
244 | 248 |
| 249 |
| 250 /* |
| 251 * Return 1 if PID exists in the current process list, else 0. |
| 252 */ |
| 253 int |
| 254 pid_exists(long pid) |
| 255 { |
| 256 int kill_ret; |
| 257 if (pid < 0) { |
| 258 return 0; |
| 259 } |
| 260 |
| 261 // if kill returns success of permission denied we know it's a valid PID |
| 262 kill_ret = kill(pid , 0); |
| 263 if ((0 == kill_ret) || (EPERM == errno)) { |
| 264 return 1; |
| 265 } |
| 266 |
| 267 // otherwise return 0 for PID not found |
| 268 return 0; |
| 269 } |
| 270 |
OLD | NEW |