From bc33a5def48d12c8d9459a5faed3b37ad65dc07e Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Tue, 15 Oct 2019 14:23:49 +0200 Subject: [PATCH] Add kore.proc.pid, returns the PID of the proc. --- include/kore/python_methods.h | 8 ++++++++ src/python.c | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/include/kore/python_methods.h b/include/kore/python_methods.h index 48acfdb..dadf1e8 100644 --- a/include/kore/python_methods.h +++ b/include/kore/python_methods.h @@ -539,10 +539,18 @@ static PyMethodDef pyproc_methods[] = { METHOD(NULL, NULL, -1), }; +static PyObject *pyproc_get_pid(struct pyproc *, void *); + +static PyGetSetDef pyproc_getset[] = { + GETTER("pid", pyproc_get_pid), + GETTER(NULL, NULL), +}; + static PyTypeObject pyproc_type = { PyVarObject_HEAD_INIT(NULL, 0) .tp_name = "kore.proc", .tp_doc = "async process", + .tp_getset = pyproc_getset, .tp_methods = pyproc_methods, .tp_basicsize = sizeof(struct pyproc), .tp_dealloc = (destructor)pyproc_dealloc, diff --git a/src/python.c b/src/python.c index 712804e..1e156e0 100644 --- a/src/python.c +++ b/src/python.c @@ -3690,6 +3690,12 @@ pyproc_close_stdin(struct pyproc *proc, PyObject *args) Py_RETURN_TRUE; } +static PyObject * +pyproc_get_pid(struct pyproc *proc, void *closure) +{ + return (PyLong_FromLong(proc->pid)); +} + static void pyproc_op_dealloc(struct pyproc_op *op) {