unix pid

Róbert Balogh (IJ/ETH) robert.balogh@REDACTED
Sun Jul 10 09:01:13 CEST 2005


Hej Michael,

Thanks for Your answer. So this is what I don't know, how it possible to associate the UNIX pid to erlang pid :-( Maybe some other erlang experts will be knows.

thanks again,

br,
/Robi

-----Original Message-----
From: owner-erlang-questions@REDACTED
[mailto:owner-erlang-questions@REDACTED]
Sent: Sunday, July 10, 2005 3:25 AM
To: erlang-questions@REDACTED
Subject: Re: unix pid



I think I understand your question.  

Perhaps I am misunderstanding the Erlang documentation.

os:cmd/1 says...
---------------------------------------------
cmd(Command) -> string()

Types:
Command = string() | atom()

Executes Command in a command shell of the target OS and returns the result as a string. This function is a replacement of the previous unix:cmd/1; on a Unix platform they are equivalent.

Examples:
LsOut = os:cmd("ls"), % on unix platform
DirOut = os:cmd("dir"), % on Win32 platform
---------------------------------------------

If I do the following from my (Linux) system prompt

$ sleep 97 &
[3] 11702
$ ps xauw | egrep sleep | egrep -v
mmcdanie 11702  0.0  0.1  2732  672 pts/49   S    18:23   0:00 sleep 97
$

Since the Pid is returned as a string from the command prompt, I would expect the following
from within Erlang to return the Pid also, though it does not.

$ erl
Erlang (BEAM) emulator version 5.4.8 [hipe]

Eshell V5.4.8  (abort with ^G)
1> os:cmd("sleep 97 &").
[]
2> q().
ok
$

I do not know how to associate a specific Unix PID with the specific Erlang
instance/Pid that created the Unix PID.

~Michael


On Sat, Jul 09, 2005 at 06:15:52PM +0200, Róbert Balogh (IJ/ETH) wrote:
> Hej Michael,
> 
> Sorry for that the not clear question. So I'd like to know the pid of the UNIX process what is exits by erlang os:cmd(..). I know what You're sent to me. The second example is closer to my question, but it's not perfect, because:
> - I start several erlang nodes in the same unix
> - and in every erlang node I'm starting the same unix process (!!) and I have to know the unix process what I created at the start phase, because when this erlang process is terminate must be terminate the UNIX process to what is belongs to this erlang process. If I follow the second example it's not possible to separate the UNIX process which belongs to which erlang if the several erlang processes in the erlang nodes are starting in the same time.
> 
> Is this clearer? Sorry again for this...
> 
> br,
> /Robi
> 
> -----Original Message-----
> From: Michael McDaniel [mailto:erlang@REDACTED]
> Sent: Saturday, July 09, 2005 6:05 PM
> To: Róbert Balogh (IJ/ETH)
> Cc: Erlang question (E-mail)
> Subject: Re: unix pid
> 
> 
> On Sat, Jul 09, 2005 at 03:15:13PM +0200, Róbert Balogh (IJ/ETH) wrote:
> > Hej erlang experts,
> > 
> > I'd like to ask You if I'm on UNIX/Linux system and I do eq: os:cmd(cmdtool). in erlang, how possible to know the pid of that process what is created by this?
> > 
> > thanks a lot for Your help.
> > 
> > br,
> > /Robi
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> I am not certain I understand your question.  The following may be of assistance.
> 
> The first example (1>, 2>) shows Erlang system information about the PID returned from the
> Erlang process.  Note I ran spawn/3 otherwise the os:cmd/1 would not return until after
> "sleep 7" finished.
> 
> The second example (3>, 4>) shows host OS PID of the background 'find /' process.
> Note I ran "find / &" as background process.
> 
> 
> $ erl
> Erlang (BEAM) emulator version 5.4.8 [hipe]
> 
> Eshell V5.4.8  (abort with ^G)
> 1> spawn(os, cmd, ["sleep 7"]).
> <0.35.0>
> 2> i(0,35,0).
> [{current_function,{os,unix_cmd,1}},
>  {initial_call,{os,cmd,1}},
>  {status,waiting},
>  {message_queue_len,0},
>  {messages,[]},
>  {links,[<0.36.0>]},
>  {dictionary,[]},
>  {trap_exit,false},
>  {error_handler,error_handler},
>  {priority,normal},
>  {group_leader,<0.24.0>},
>  {heap_size,233},
>  {stack_size,3},
>  {reductions,14},
>  {garbage_collection,[{fullsweep_after,65535}]}]
> 3> 
> 3> os:cmd("find / &").
> []
> 4> os:cmd("ps xauw | egrep find | egrep -v grep").
> "mmcdanie 10468  0.0  0.1  2552  700 ?        D    08:55   0:03 find /\n"
> 5> 
> 
> ~Michael



More information about the erlang-questions mailing list