Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9194289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:22:35+00:00 2026-06-17T21:22:35+00:00

Given two linked processes child and parent , how does process child detect that

  • 0

Given two linked processes child and parent, how does process child detect that parent exits (terminates) normally?

I, as an absolute Erlang beginner, thought that a process, when it has nothing else to do, exited using exit(normal). This then signals all linked processes, where

  • the behaviour of processes that have trap_exit set to false is to ignore the signal, and
  • the behaviour of processes that have trap_exit set to true is to generate the message {'EXIT', pid, normal} where pid is the process id of the terminating process.

My reason for thinking this is Learn You Some Erlang for Great Good and the Erlang documentation which states the following.

A process is said to terminate normally, if the exit reason is the atom normal. A process with no more code to execute terminates normally.

Apparently that is wrong (?), because exit(normal) shows ** exception exit: normal in the command prompt and makes the code below work. Exiting because there is no more code to execute does not generate the exception and does not make my code work.

As an example, consider the following code.

-module(test).
-export([start/0,test/0]).

start() ->
     io:format("Parent (~p): started!\n",[self()]),
     P = spawn_link(?MODULE,test,[]),
     io:format(
        "Parent (~p): child ~p spawned. Waiting for 5 seconds\n",[self(),P]),
     timer:sleep(5000),
     io:format("Parent (~p): dies out of boredom\n",[self()]),
     ok. 

test() ->
     io:format("Child (~p): I'm... alive!\n",[self()]),
     process_flag(trap_exit, true),
     loop().

loop() ->
     receive
          Q = {'EXIT',_,_} ->
                io:format("Child process died together with parent (~p)\n",[Q]);
          Q ->
                io:format("Something else happened... (~p)\n",[Q])
     after
          2000 -> io:format("Child (~p): still alive...\n", [self()]), loop()
     end.

This produces output as follows.

(erlide@127.0.0.1)> test:start().
Parent (<0.145.0>): started!
Parent (<0.145.0>): child <0.176.0> spawned. Waiting for 5 seconds
Child (<0.176.0>): I'm... alive!
Child (<0.176.0>): still alive...
Child (<0.176.0>): still alive...
Parent (<0.145.0>): dies out of boredom
ok
(erlide@127.0.0.1)10> Child (<0.176.0>): still alive...
Child (<0.176.0>): still alive...
Child (<0.176.0>): still alive...
Child (<0.176.0>): still alive...
Child (<0.176.0>): still alive...
Child (<0.176.0>): still alive...
Child (<0.176.0>): still alive...
exit(pid(0,176,0),something).
Child process died together with parent ({'EXIT',<0.194.0>,something})

If had to manually execute the exit(pid(0,176,0),something) command to keep the child from staying alive forever.
Changing ok. in start to exit(normal) makes the execution go like this

(erlide@127.0.0.1)3> test:start().
Parent (<0.88.0>): started!
Parent (<0.88.0>): child <0.114.0> spawned. Waiting for 5 seconds
Child (<0.114.0>): I'm... alive!
Child (<0.114.0>): still alive...
Child (<0.114.0>): still alive...
Parent (<0.88.0>): dies out of boredom
Child process died together with parent ({'EXIT',<0.88.0>,normal})
** exception exit: normal

My concrete questions are the following.

  1. How can I make the above code work as expected. That is, how can I make sure the child process dies together with the parent process without changing the parent process?
  2. Why does exit(normal) generate a ** exception exit: normal in the CLI? It is hard for me to think of an exception as something that is normal. What does the scentence in the Erlang documentation mean?

I think these must be extremely basic questions, but I can’t seem to figure this out….
I am using Erlang 5.9.3.1 on Windows (x64).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:22:36+00:00Added an answer on June 17, 2026 at 9:22 pm

    Erlang shell has the worker for evaluating commands as a separate process, and all commands you type run by the same process. When you your start function finished, worker still alive, and when you kill it by exit(), shell understand as worker exception (because worker will never die in normal case).

    So:

    1. You should run start as separate process by spawn or spawn_link
    2. CLI logs all worker exits as exception and normal too

    P.S. sorry for my english

    P.P.S. spawn(fun() -> test:start() end). works as expected

    4> spawn(fun() -> test:start() end).
    Parent (<0.41.0>): started!
    <0.41.0>
    Parent (<0.41.0>): child <0.42.0> spawned. Waiting for 5 seconds
    Child (<0.42.0>): I'm... alive!
    Child (<0.42.0>): still alive...
    Child (<0.42.0>): still alive...
    Parent (<0.41.0>): dies out of boredom
    Child process died together with parent ({'EXIT',<0.41.0>,normal})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given two unsorted single linked list of size M and N . The task
Given a linked list of integers in random order, split it into two new
Given two sorted linked lists, L1 and L2, a solution to compute their intersection
I have a table that records a history of child items linked to a
I have written a function that merges two linked list. (Note that the function
We have to check if two given linked lists contain the same data. Order
I have two objects that are linked by a foreign key relationship and I
I need a little help with my new assignment. Problem: Given Two Linked List
Given two data frames: C1<-c(3,4,4,4,5) C2<-c(3,7,3,4,5) C3<-c(5,6,3,7,4) DF<-data.frame(C1=C1,C2=C2,C3=C3) DF C1 C2 C3 1 3
Given two tuples of the same arity, how can I lexicographically compare them? It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.