Sun Jul 10 03:24:31 CEST 2005
I think I understand your question.
Perhaps I am misunderstanding the Erlang documentation.
cmd(Command) -> string()
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.
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 &
$ 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.
Erlang (BEAM) emulator version 5.4.8 [hipe]
Eshell V5.4.8 (abort with ^G)
1> os:cmd("sleep 97 &").
I do not know how to associate a specific Unix PID with the specific Erlang
instance/Pid that created the Unix PID.
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...
> -----Original Message-----
> From: Michael McDaniel [mailto:]
> 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"]).
> 2> i(0,35,0).
> 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"
More information about the erlang-questions