Question

When the child exits (either normally or on an error) I want to take some actions. Do I use erlang:monitor/2? And if so how do I get the pid? Also, will I be able to see why it stopped?

Was it helpful?

Solution

Yes, monitor will do the job.

You will get back: {'DOWN', MonitorRef, Type, Object, Info}

Where the Object is the pid and Info is the exit reason

You can also do with link and trap_exit, but links are bi-directional so you'd take that child out with you if the parent died.

The easiest way to get the PID of the child process will be to have the child register itself with the listener (the one using monitor) when it starts. Have it send self() and then the listener can monitor that PID.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top