Skip to content

Commit

Permalink
Merge pull request #230 from luvit/getpid
Browse files Browse the repository at this point in the history
add process.pid, fix #218
  • Loading branch information
philips committed May 29, 2012
2 parents 6899bd9 + 3288560 commit 641eeb2
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/luvit/luvit.lua
Expand Up @@ -133,6 +133,9 @@ process.env = setmetatable({}, {
end
})
--Retrieve PID
process.pid = native.getpid()
-- Copy date and time over from lua os module into luvit os module
local OLD_OS = require('os')
local OS_BINDING = require('os_binding')
Expand Down
3 changes: 2 additions & 1 deletion src/luv.c
Expand Up @@ -66,7 +66,8 @@ static const luaL_reg luv_f[] = {
/* Process functions */
{"spawn", luv_spawn},
{"processKill", luv_process_kill},

{"getpid", luv_getpid},

/* Stream functions */
{"shutdown", luv_shutdown},
{"listen", luv_listen},
Expand Down
1 change: 1 addition & 0 deletions src/luv_portability.h
Expand Up @@ -20,6 +20,7 @@

#if _MSC_VER
#define snprintf _snprintf
#define getpid _getpid
#endif

#if defined(__OpenBSD__) || defined(__MINGW32__) || defined(_MSC_VER)
Expand Down
6 changes: 6 additions & 0 deletions src/luv_process.c
Expand Up @@ -32,6 +32,12 @@ void luv_process_on_exit(uv_process_t* handle, int exit_status, int term_signal)

}

/* Retrieves Process ID */
int luv_getpid(lua_State* L){
int pid = getpid();
lua_pushinteger(L, pid);
return 1;
}

/* Initializes uv_process_t and starts the process. */
int luv_spawn(lua_State* L) {
Expand Down
1 change: 1 addition & 0 deletions src/luv_process.h
Expand Up @@ -26,5 +26,6 @@

int luv_spawn(lua_State* L);
int luv_process_kill(lua_State* L);
int luv_getpid(lua_State* L);

#endif
2 changes: 2 additions & 0 deletions tests/test-process.lua
Expand Up @@ -23,6 +23,8 @@ end

test()

assert(process.pid ~= nil)

process:on('exit', function()
assert(environmentTestResult == true)
end)

0 comments on commit 641eeb2

Please sign in to comment.