title: kill process and run a program in erlang
body: <p>I develop a program in erlang </p>
  
  <p>I run this program with this command:</p>
  
  <pre><code> ./build.sh &amp;&amp; ./deploy.sh ./erl_start.sh
  </code></pre>
  
  <p>I want know to do a <strong>test</strong> in the function <strong>verify</strong>  which are stored in the file model.erl of my program</p>
  
  <p>in the function <strong>verify</strong>  I should find and kill the process of my program ( current program)
  and I want to run the program</p>
  
  <pre><code>verify(Val)-&gt;
  if Val =:=40 -&gt;
  %% kill the process of my program
  %% run this commande ./build.sh &amp;&amp; ./deploy.sh ./erl_start.sh
  
  true -&gt; ok
  
  end.
  </code></pre>
  
  <p>so I think that I will try with</p>
  
  <pre><code>  verify(Val)-&gt;
      if Val =:=40 -&gt;
    exit(Pid,Reason), %%  but I should know the pid of the current program
     os_cmd("./build.sh &amp;&amp; ./deploy.sh ./erl_start.sh");
  
      true -&gt; ok
  
      end.
  </code></pre>
  
  <p>knowing the pid of the current programm  --> I have an application which is running and in the code of this application I should have a way to know the pid of this application in order to make it stop</p>
  
  <p>currently</p>
  
  <p>I try with this function:</p>
  
  <pre><code>verify(Val)-&gt;
      if Val =:=40 -&gt;
  Pid = self(), 
  
  io:format("~w~n",[Pid]),
  spawn(fun() -&gt; exit(Pid, kill) end),
      LsOut = os:cmd("./build.sh &amp;&amp; ./deploy.sh &amp;&amp; ./erl_start.sh");
  
      true -&gt; ok
  
      end.
  </code></pre>
  
  <p>and when I test this function I have this error :</p>
  
  <pre><code>1&gt; model:verify(40).
  &lt;0.144.0&gt;
  ** exception exit: killed
  </code></pre>
  
  <p>My goal is:</p>
  
  <p>I have an application developed in Erlang to run this application I need to do: <strong>./build.sh &amp;&amp; ./deploy.sh &amp;&amp; ./erl_start.sh</strong></p>
  
  <p>I want to make a function (in our case it is the function verify) that will do the same thing as <strong>Ctrl + C and after do ./build.sh &amp;&amp; ./deploy.sh &amp;&amp; ./erl_start.sh
  meanig stop the application and run again this application</strong></p>
  
  <p>I also test your command and I have this result :</p>
  
  <pre><code>1&gt; [io:format("~p : ~p~n",[Pid,erlang:process_info(Pid,current_function)]) || Pid &lt;- processes()].
  &lt;0.0.0&gt; : {current_function,{init,loop,1}}
  &lt;0.3.0&gt; : {current_function,{erl_prim_loader,loop,3}}
  &lt;0.5.0&gt; : {current_function,{gen_event,fetch_msg,5}}
  &lt;0.6.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.8.0&gt; : {current_function,{application_master,main_loop,2}}
  &lt;0.9.0&gt; : {current_function,{application_master,loop_it,4}}
  &lt;0.10.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.11.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.12.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.13.0&gt; : {current_function,{global,loop_the_locker,1}}
  &lt;0.14.0&gt; : {current_function,{global,collect_deletions,2}}
  &lt;0.15.0&gt; : {current_function,{global,loop_the_registrar,0}}
  &lt;0.16.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.18.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.19.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.20.0&gt; : {current_function,{code_server,loop,1}}
  &lt;0.21.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.22.0&gt; : {current_function,{standard_error,server_loop,1}}
  &lt;0.23.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.24.0&gt; : {current_function,{user_drv,server_loop,5}}
  &lt;0.25.0&gt; : {current_function,{group,server_loop,3}}
  &lt;0.26.0&gt; : {current_function,{group,server_loop,3}}
  &lt;0.27.0&gt; : {current_function,{shell,shell_rep,4}}
  &lt;0.28.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.29.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.36.0&gt; : {current_function,{application_master,main_loop,2}}
  &lt;0.37.0&gt; : {current_function,{application_master,loop_it,4}}
  &lt;0.38.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.39.0&gt; : {current_function,{gen_event,fetch_msg,5}}
  &lt;0.40.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.41.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.44.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.45.0&gt; : {current_function,{mnesia_locker,loop,1}}
  &lt;0.46.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.47.0&gt; : {current_function,{mnesia_tm,doit_loop,1}}
  &lt;0.48.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.49.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.53.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.54.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.63.0&gt; : {current_function,{disk_log,loop,1}}
  &lt;0.65.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.66.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.67.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.68.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.69.0&gt; : {current_function,{mnesia_late_loader,loop,1}}
  &lt;0.105.0&gt; : {current_function,{application_master,main_loop,2}}
  &lt;0.106.0&gt; : {current_function,{application_master,loop_it,4}}
  &lt;0.107.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.108.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.109.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.110.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.111.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.112.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.113.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.114.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.115.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.117.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.118.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.119.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.120.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.121.0&gt; : {current_function,{prim_inet,accept0,2}}
  &lt;0.123.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.124.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.125.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.126.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.127.0&gt; : {current_function,{prim_inet,accept0,2}}
  &lt;0.129.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.130.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.131.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.132.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.133.0&gt; : {current_function,{prim_inet,accept0,2}}
  &lt;0.135.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.136.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.137.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.138.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.139.0&gt; : {current_function,{prim_inet,accept0,2}}
  &lt;0.140.0&gt; : {current_function,{gen_server,loop,6}}
  &lt;0.143.0&gt; : {current_function,{os,start_port_srv_loop,2}}
  &lt;0.144.0&gt; : {current_function,{erl_eval,do_apply,5}}
  [ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,
   ok,ok,ok,ok,ok,ok,ok,ok,ok,ok|...]
  </code></pre>
  
  <p>and with the second command I have :</p>
  
  <pre><code>1&gt; [io:format("~p : ~p~n",[Pid,erlang:process_info(Pid,initial_call)]) || Pid &lt;- processes()]. 
  &lt;0.0.0&gt; : {initial_call,{otp_ring0,start,2}}
  &lt;0.3.0&gt; : {initial_call,{erlang,apply,2}}
  &lt;0.5.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.6.0&gt; : {initial_call,{erlang,apply,2}}
  &lt;0.8.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.9.0&gt; : {initial_call,{application_master,start_it,4}}
  &lt;0.10.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.11.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.12.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.13.0&gt; : {initial_call,{erlang,apply,2}}
  &lt;0.14.0&gt; : {initial_call,{erlang,apply,2}}
  &lt;0.15.0&gt; : {initial_call,{erlang,apply,2}}
  &lt;0.16.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.18.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.19.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.20.0&gt; : {initial_call,{erlang,apply,2}}
  &lt;0.21.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.22.0&gt; : {initial_call,{standard_error,server,2}}
  &lt;0.23.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.24.0&gt; : {initial_call,{user_drv,server,2}}
  &lt;0.25.0&gt; : {initial_call,{group,server,3}}
  &lt;0.26.0&gt; : {initial_call,{group,server,3}}
  &lt;0.27.0&gt; : {initial_call,{erlang,apply,2}}
  &lt;0.28.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.29.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.36.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.37.0&gt; : {initial_call,{application_master,start_it,4}}
  &lt;0.38.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.39.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.40.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.41.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.44.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.45.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.46.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.47.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.48.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.49.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.53.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.54.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.63.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.65.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.66.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.67.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.68.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.69.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.105.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.106.0&gt; : {initial_call,{application_master,start_it,4}}
  &lt;0.107.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.108.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.109.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.110.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.111.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.112.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.113.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.114.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.115.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.117.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.118.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.119.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.120.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.121.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.123.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.124.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.125.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.126.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.127.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.129.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.130.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.131.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.132.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.133.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.135.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.136.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.137.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.138.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.139.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.140.0&gt; : {initial_call,{proc_lib,init_p,5}}
  &lt;0.143.0&gt; : {initial_call,{erlang,apply,2}}
  &lt;0.144.0&gt; : {initial_call,{erlang,apply,2}}
  [ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,
   ok,ok,ok,ok,ok,ok,ok,ok,ok,ok|...]
  </code></pre>