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"
|
[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 the ID of the given process.
|
||||||
*
|
*
|
||||||
* Returns nil if the process was not found.
|
* Returns nil if the process was not found.
|
||||||
*
|
*
|
||||||
* If the first parameter is nil,
|
* @function pidof
|
||||||
* returns the ID of the current running process.
|
* @usage process.pidof("init")
|
||||||
*
|
* @tparam string process The process to look up.
|
||||||
* @function pid
|
|
||||||
* @usage process.pid("init")
|
|
||||||
* @tparam[opt] string process The process to look up.
|
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
process_pid(lua_State *L)
|
process_pidof(lua_State *L)
|
||||||
{
|
{
|
||||||
const char *process; /* parameter 1 (string) */
|
const char *process; /* parameter 1 (string) */
|
||||||
char *command; /* pidof command buffer */
|
char *command; /* pidof command buffer */
|
||||||
|
@ -268,6 +277,7 @@ process_terminate(lua_State *L)
|
||||||
static const luaL_Reg proclib[] = {
|
static const luaL_Reg proclib[] = {
|
||||||
{"kill", process_kill},
|
{"kill", process_kill},
|
||||||
{"pid", process_pid},
|
{"pid", process_pid},
|
||||||
|
{"pidof", process_pidof},
|
||||||
{"send", process_send},
|
{"send", process_send},
|
||||||
{"signum", process_signum},
|
{"signum", process_signum},
|
||||||
{"terminate", process_terminate},
|
{"terminate", process_terminate},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue