diff options
author | Matthias Lang <[email protected]> | 2010-08-19 15:12:26 +0200 |
---|---|---|
committer | Patrik Nyblom <[email protected]> | 2012-04-17 16:11:26 +0200 |
commit | e2277e240790930563b0833854e7bc6a8338cf5c (patch) | |
tree | 7cadd3a34cd454ff4b26bfcc2827a6a201520cc7 /erts/emulator/beam/erl_bif_info.c | |
parent | f1a49c45e4b2ec746407fd777ba31fec6cab118e (diff) | |
download | otp-e2277e240790930563b0833854e7bc6a8338cf5c.tar.gz otp-e2277e240790930563b0833854e7bc6a8338cf5c.tar.bz2 otp-e2277e240790930563b0833854e7bc6a8338cf5c.zip |
Extend erlang:port_info/1,2 to show the OS pid of a spawned process
When spawning OS (unix) processes with erlang:open_port, store the
resulting unix pid so that it can be queried later on using
erlang:port_info/1,2.
Diffstat (limited to 'erts/emulator/beam/erl_bif_info.c')
-rw-r--r-- | erts/emulator/beam/erl_bif_info.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/erts/emulator/beam/erl_bif_info.c b/erts/emulator/beam/erl_bif_info.c index 060a52d220..4dcfe997d4 100644 --- a/erts/emulator/beam/erl_bif_info.c +++ b/erts/emulator/beam/erl_bif_info.c @@ -2765,7 +2765,8 @@ port_info_1(BIF_ALIST_1) am_id, am_connected, am_input, - am_output + am_output, + am_os_pid }; Eterm items[ASIZE(keys)]; Eterm result = NIL; @@ -2822,6 +2823,7 @@ port_info_1(BIF_ALIST_1) ** name String ** input Number of bytes input from port program ** output Number of bytes output to the port program +** os_pid The child's process ID */ BIF_RETTYPE port_info_2(BIF_ALIST_2) @@ -2922,6 +2924,18 @@ static BIF_RETTYPE port_info(Process* p, Eterm portid, Eterm item) hp = HAlloc(p, hsz); res = erts_bld_uint(&hp, NULL, n); } + else if (item == am_os_pid) { + if (prt->os_pid >= 0) { + Uint hsz = 3; + Uint n = prt->os_pid; + (void) erts_bld_uint(NULL, &hsz, n); + hp = HAlloc(p, hsz); + res = erts_bld_uint(&hp, NULL, n); + } else { + hp = HAlloc(p, 3); + res = am_undefined; + } + } else if (item == am_registered_name) { RegProc *reg; reg = prt->reg; |