From 69b422727184d73531a6e1d9efa26afb56bcded0 Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Sun, 2 Jul 2023 08:39:46 +1200 Subject: [PATCH] Split process.pid into two functions: process.pid (get the current process's PID) and process.pidof (get another process's PID) --- lprocess.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lprocess.c b/lprocess.c index 38e8b99..d88f2d5 100644 --- a/lprocess.c +++ b/lprocess.c @@ -78,20 +78,29 @@ static const char *signals[] = { [SIGUSR2] = "SIGUSR2" }; +/*** + * Returns the PID of the current process. + * + * @function pid + * @usage local pid = process.pid() + */ +static int +process_pid(lua_State *L) +{ + lua_pushinteger(L, getpid()); /* push current process pid */ + return 1; +} /*** * Returns the ID of the given process. * * Returns nil if the process was not found. * - * If the first parameter is nil, - * returns the ID of the current running process. - * - * @function pid - * @usage process.pid("init") - * @tparam[opt] string process The process to look up. + * @function pidof + * @usage process.pidof("init") + * @tparam string process The process to look up. */ static int -process_pid(lua_State *L) +process_pidof(lua_State *L) { const char *process; /* parameter 1 (string) */ char *command; /* pidof command buffer */ @@ -268,6 +277,7 @@ process_terminate(lua_State *L) static const luaL_Reg proclib[] = { {"kill", process_kill}, {"pid", process_pid}, + {"pidof", process_pidof}, {"send", process_send}, {"signum", process_signum}, {"terminate", process_terminate},