简体   繁体   中英

Erlang simple_one_for_one supervisor terminate_child isn't working

According to the Erlang docs, you can use the supervisor:terminate_child function with simple_one_for_one supervisors as long as you pass in the PID of the process instead of the child spec identifier. However, this doesn't seem to work for me in practice, and instead the function returns back {error, simple_one_for_one}. Here's what I'm seeing:

(client-1@nick-desktop)9> supervisor:which_children(my_sup).
[{undefined,<0.544.0>,worker,[cf_server]}]
(client-1@nick-desktop)10> P.
<0.544.0>
(client-1@nick-desktop)11> supervisor:terminate_child(my_sup, P).
{error,simple_one_for_one}

Am I doing something wrong, or are the Erlang docs inaccurate? If I can't stop the process with supervisor:terminate_child, should I just call exit(P, shutdown) instead?

What version of erlang are you running? I think supervisor:terminate_child/2 was only allowed for simple_one_for_one supervisors starting in R14B03.

Author: Siri Hansen Date: Tue Apr 12 16:47:17 2011 +0200

 Allow supervisor:terminate_child(SupRef,Pid) for simple_one_for_one supervisor:terminate_child/2 was not allowed if the supervisor used restart strategy simple_one_for_one. This is now changed so that children of this type of supervisors can be terminated by specifying the child's Pid. 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM