title: Erlang supervisor/gen_server exception exit: noproc
body: <p>I'm going insane right now trying to figure out what the problem to this is.</p>
  
  <p>Basically I just want to set up an easy Supervisor with 1 server and 1 gen_event-behaviour module.</p>
  
  <p>Now the problem is that I can't get it to start anymore, the supervisor that is.</p>
  
  <p>I get this error no matter what I do:
  ** exception exit: noproc</p>
  
  <p>and when using the text-tracer it shows that it happends in sRPG_supervisor:init/1. And with this you think there's something wrong with the code, but I get exactly the same thing when I run other peoples examples of this(I've downloaded Joe Armstrongs examples and tested the sellaprime_supervisor with the same result).</p>
  
  <p>It used to start fine when I ran it in my virtual Ubuntu installation. Then I set it up so I could code in Windows but I never even tested that the simplest form of this worked, and obviously it don't for some reason.</p>
  
  <p>So if someone has had a similar problem, would be great to find a solution!
  I'm using erl6.3 as the Erlang version with OTP 17.</p>
  
  <p>Here's the code that I'm using, just a buildup from the Emacs generated skeleton:
  sRPG_supervisor.erl</p>
  
  <pre><code>-module(sRPG_supervisor).
  
  -behaviour(supervisor).
  
  %% API
  -export([start_link/0, start_link/1, start/0, start_in_shell_for_testing/0]).
  
  %% Supervisor callbacks
  -export([init/1]).
  
  -define(SERVER, ?MODULE).
  
  %%%===================================================================
  %%% API functions
  %%%===================================================================
  
  %%--------------------------------------------------------------------
  %% @doc
  %% Starts the supervisor
  %%
  %% @spec start_link() -&gt; {ok, Pid} | ignore | {error, Error}
  %% @end
  %%--------------------------------------------------------------------
  start_link() -&gt;
      supervisor:start_link({local, ?SERVER}, ?MODULE, []).
  
  start() -&gt;
      spawn(fun() -&gt;
            supervisor:start_link({local, ?SERVER}, ?MODULE, _Arg = [])
        end).
  
  start_in_shell_for_testing() -&gt;
      {ok, Pid} = supervisor:start_link({local, ?SERVER}, ?MODULE, _Arg = []),
      unlink(Pid).
  
  start_link(Args) -&gt;
      supervisor:start_link({local, ?SERVER}, ?MODULE, Args).
  
  
  %%%===================================================================
  %%% Supervisor callbacks
  %%%===================================================================
  
  %%--------------------------------------------------------------------
  %% @private
  %% @doc
  %% Whenever a supervisor is started using supervisor:start_link/[2,3],
  %% this function is called by the new process to find out about
  %% restart strategy, maximum restart frequency and child
  %% specifications.
  %%
  %% @spec init(Args) -&gt; {ok, {SupFlags, [ChildSpec]}} |
  %%                     ignore |
  %%                     {error, Reason}
  %% @end
  %%--------------------------------------------------------------------
  init([]) -&gt;
      %% Install sRPG event/error handler
      gen_event:swap_handler(alarm_handler, {alarm_handler, swap}, {sRPG_event_handler, xyz}),
  
  
  
      RestartStrategy = one_for_one,
      MaxRestarts = 1000,
      MaxSecondsBetweenRestarts = 3600,
  
      SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts},
  
      Restart = permanent,
      Shutdown = 2000,
      Type = worker,
  
      AChild = {sRPG_server, {sRPG_server, start_link, []},
            Restart, Shutdown, Type, [sRPG_server]},
  
      {ok, {SupFlags, [AChild]}}.
  </code></pre>
  
  <p>sRPG_server.erl</p>
  
  <pre><code>-module(sRPG_server).
  
  -behaviour(gen_server).
  
  %% API
  -export([start_link/0, testServer/0]).
  
  %% gen_server callbacks
  -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
       terminate/2, code_change/3]).
  
  -define(SERVER, ?MODULE).
  
  -record(state, {}).
  
  %%%===================================================================
  %%% API
  %%%===================================================================
  
  testServer() -&gt;
      gen_server:call(?MODULE, {test, test}).
  
  
  %%--------------------------------------------------------------------
  %% @doc
  %% Starts the server
  %%
  %% @spec start_link() -&gt; {ok, Pid} | ignore | {error, Error}
  %% @end
  %%--------------------------------------------------------------------
  start_link() -&gt;
      gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
  
  %%%===================================================================
  %%% gen_server callbacks
  %%%===================================================================
  
  %%--------------------------------------------------------------------
  %% @private
  %% @doc
  %% Initializes the server
  %%
  %% @spec init(Args) -&gt; {ok, State} |
  %%                     {ok, State, Timeout} |
  %%                     ignore |
  %%                     {stop, Reason}
  %% @end
  %%--------------------------------------------------------------------
  init([]) -&gt;
      %% Note we must set trap_exit = true if we want
      %% terminate/2 to be called when the application is stopped
      process_flag(trap_exit, true),
      %MainGamePid = gameSystem:start(),
  
      io:format("~p starting~n", [?MODULE]),
      {ok, #state{}}.
  
  %%--------------------------------------------------------------------
  %% @private
  %% @doc
  %% Handling call messages
  %%
  %% @spec handle_call(Request, From, State) -&gt;
  %%                                   {reply, Reply, State} |
  %%                                   {reply, Reply, State, Timeout} |
  %%                                   {noreply, State} |
  %%                                   {noreply, State, Timeout} |
  %%                                   {stop, Reason, Reply, State} |
  %%                                   {stop, Reason, State}
  %% @end
  %%--------------------------------------------------------------------
  handle_call({test, test}, _From, State) -&gt;
      io:format("TEST TEST TEST ~n"),
      Reply = ok,
      {reply, Reply, State};
  handle_call(_Request, _From, State) -&gt;
      Reply = ok,
      {reply, Reply, State}.
  
  %%--------------------------------------------------------------------
  %% @private
  %% @doc
  %% Handling cast messages
  %%
  %% @spec handle_cast(Msg, State) -&gt; {noreply, State} |
  %%                                  {noreply, State, Timeout} |
  %%                                  {stop, Reason, State}
  %% @end
  %%--------------------------------------------------------------------
  handle_cast(_Msg, State) -&gt;
      {noreply, State}.
  
  %%--------------------------------------------------------------------
  %% @private
  %% @doc
  %% Handling all non call/cast messages
  %%
  %% @spec handle_info(Info, State) -&gt; {noreply, State} |
  %%                                   {noreply, State, Timeout} |
  %%                                   {stop, Reason, State}
  %% @end
  %%--------------------------------------------------------------------
  handle_info(_Info, State) -&gt;
      {noreply, State}.
  
  %%--------------------------------------------------------------------
  %% @private
  %% @doc
  %% This function is called by a gen_server when it is about to
  %% terminate. It should be the opposite of Module:init/1 and do any
  %% necessary cleaning up. When it returns, the gen_server terminates
  %% with Reason. The return value is ignored.
  %%
  %% @spec terminate(Reason, State) -&gt; void()
  %% @end
  %%--------------------------------------------------------------------
  terminate(_Reason, _State) -&gt;
      ok.
  
  %%--------------------------------------------------------------------
  %% @private
  %% @doc
  %% Convert process state when code is changed
  %%
  %% @spec code_change(OldVsn, State, Extra) -&gt; {ok, NewState}
  %% @end
  %%--------------------------------------------------------------------
  code_change(_OldVsn, State, _Extra) -&gt;
      {ok, State}.
  
  %%%===================================================================
  %%% Internal functions
  %%%===================================================================
  </code></pre>
  
  <p>sRPG_event_handler.erl</p>
  
  <pre><code>-module(sRPG_event_handler).
  
  -behaviour(gen_event).
  
  %% API
  -export([start_link/0, add_handler/0]).
  
  %% gen_event callbacks
  -export([init/1, handle_event/2, handle_call/2, 
       handle_info/2, terminate/2, code_change/3]).
  
  -define(SERVER, ?MODULE).
  
  -record(state, {}).
  
  %%%===================================================================
  %%% gen_event callbacks
  %%%===================================================================
  
  %%--------------------------------------------------------------------
  %% @doc
  %% Creates an event manager
  %%
  %% @spec start_link() -&gt; {ok, Pid} | {error, Error}
  %% @end
  %%--------------------------------------------------------------------
  start_link() -&gt;
      gen_event:start_link({local, ?SERVER}).
  
  %%--------------------------------------------------------------------
  %% @doc
  %% Adds an event handler
  %%
  %% @spec add_handler() -&gt; ok | {'EXIT', Reason} | term()
  %% @end
  %%--------------------------------------------------------------------
  add_handler() -&gt;
      gen_event:add_handler(?SERVER, ?MODULE, []).
  
  %%%===================================================================
  %%% gen_event callbacks
  %%%===================================================================
  
  %%--------------------------------------------------------------------
  %% @private
  %% @doc
  %% Whenever a new event handler is added to an event manager,
  %% this function is called to initialize the event handler.
  %%
  %% @spec init(Args) -&gt; {ok, State}
  %% @end
  %%--------------------------------------------------------------------
  init([]) -&gt;
      io:format("*** sRPG Event Handler init ***~n"),
      {ok, #state{}};
  init(Args) -&gt;
      io:format("*** sRPG Event Handler init: ~p~n", [Args]),
      {ok, #state{}}.
  
  %%--------------------------------------------------------------------
  %% @private
  %% @doc
  %% Whenever an event manager receives an event sent using
  %% gen_event:notify/2 or gen_event:sync_notify/2, this function is
  %% called for each installed event handler to handle the event.
  %%
  %% @spec handle_event(Event, State) -&gt;
  %%                          {ok, State} |
  %%                          {swap_handler, Args1, State1, Mod2, Args2} |
  %%                          remove_handler
  %% @end
  %%--------------------------------------------------------------------
  handle_event({set_alarm, testAlarm}, State) -&gt;
      error_logger:error_msg("*** BEEP BOOP TEST ALARM ***~n"),
      {ok, State};
  handle_event({clear_alarm, testAlarm}, State) -&gt;
      error_logger:error_msg("*** Brrrrppp... Test Alarm Over ***~n"),
      {ok, State};
  handle_event(_Event, State) -&gt;
      {ok, State}.
  
  %%--------------------------------------------------------------------
  %% @private
  %% @doc
  %% Whenever an event manager receives a request sent using
  %% gen_event:call/3,4, this function is called for the specified
  %% event handler to handle the request.
  %%
  %% @spec handle_call(Request, State) -&gt;
  %%                   {ok, Reply, State} |
  %%                   {swap_handler, Reply, Args1, State1, Mod2, Args2} |
  %%                   {remove_handler, Reply}
  %% @end
  %%--------------------------------------------------------------------
  handle_call(_Request, State) -&gt;
      Reply = ok,
      {ok, Reply, State}.
  
  %%--------------------------------------------------------------------
  %% @private
  %% @doc
  %% This function is called for each installed event handler when
  %% an event manager receives any other message than an event or a
  %% synchronous request (or a system message).
  %%
  %% @spec handle_info(Info, State) -&gt;
  %%                         {ok, State} |
  %%                         {swap_handler, Args1, State1, Mod2, Args2} |
  %%                         remove_handler
  %% @end
  %%--------------------------------------------------------------------
  handle_info(_Info, State) -&gt;
      {ok, State}.
  
  %%--------------------------------------------------------------------
  %% @private
  %% @doc
  %% Whenever an event handler is deleted from an event manager, this
  %% function is called. It should be the opposite of Module:init/1 and
  %% do any necessary cleaning up.
  %%
  %% @spec terminate(Reason, State) -&gt; void()
  %% @end
  %%--------------------------------------------------------------------
  terminate(_Reason, _State) -&gt;
      ok.
  
  %%--------------------------------------------------------------------
  %% @private
  %% @doc
  %% Convert process state when code is changed
  %%
  %% @spec code_change(OldVsn, State, Extra) -&gt; {ok, NewState}
  %% @end
  %%--------------------------------------------------------------------
  code_change(_OldVsn, State, _Extra) -&gt;
      {ok, State}.
  
  %%%===================================================================
  %%% Internal functions
  %%%===================================================================
  </code></pre>
  
  <p>and here's examples of what happens:</p>
  
  <pre><code>Eshell V6.3  (abort with ^G)
  1&gt; sRPG_supervisor:start_link().
  ** exception exit: noproc
  2&gt; sRPG_supervisor:start_in_shell_for_testing().
  ** exception exit: noproc
  3&gt; ServPid = sRPG_server:start_link().
  sRPG_server starting
  {ok,&lt;0.39.0&gt;}
  4&gt; gen_server:call(sRPG_server, {test, test}).
  TEST TEST TEST 
  ok
  </code></pre>
  
  <p>As you can see the server works when called without a supervisor.</p>
  
  <p>I've looked hard at the similar problems others have had, but to no avail.</p>