Split process.pid into two functions: process.pid (get the current process's PID) and process.pidof (get another process's PID)
This commit is contained in:
parent
c62d4056e6
commit
69b4227271
1 changed files with 17 additions and 7 deletions
24
lprocess.c
24
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},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue