   end
 
   def task(parent, fun \\ (fn() -> raise "oops" end)) do
+    mon = Process.monitor(parent)
     Process.unlink(parent)
-    receive do: (:go -> fun.())
+    receive do
+      :go ->
+        fun.()
+      {:DOWN, ^mon, _, _, _} ->
+        exit(:shutdown)
+    end
   end
 
   def sub_task(parent, fun \\ (fn(_) -> raise "oops" end)) do
+    mon = Process.monitor(parent)
     Process.unlink(parent)
-    {:ok, pid} = Task.start_link(:timer, :sleep, [500])
-    receive do: (:go -> fun.(pid))
+    {:ok, pid} = Task.start_link(__MODULE__, :sleep, [self()])
+    receive do: (:sleeping -> :ok)
+    receive do
+      :go ->
+        fun.(pid)
+      {:DOWN, ^mon, _, _, _} ->
+        exit(:shutdown)
+    end
+  end
+
+  def sleep(pid) do
+    mon = Process.monitor(pid)
+    send(pid, :sleeping)
+    receive do: ({:DOWN, ^mon, _, _, _} -> exit(:shutdown))
   end
 
   def error(), do: {:error, :stop}

    {:ok, pid} = Supervisor.start_link([], [strategy: :one_for_one])
    assert capture_log(:info, fn ->
      ref = Process.monitor(pid)
      Supervisor.start_child(pid, worker(Task, [:timer, :sleep, [500]]))
      Process.exit(pid, :normal)
      receive do: ({:DOWN, ^ref, _, _, _} -> :ok)
    end) =~ ~r"""
    \[info\]  Child Task of Supervisor #PID<\d+\.\d+\.\d+> \(Supervisor\.Default\) started
    Pid: #PID<\d+\.\d+\.\d+>
    Start Call: Task.start_link\(:timer, :sleep, \[500\]\)
    """
  end


      [strategy: :one_for_one, name: __MODULE__])
    assert capture_log(:info, fn ->
      ref = Process.monitor(pid)
      Supervisor.start_child(pid, worker(Task, [__MODULE__, :sleep, [self()]]))
      Process.exit(pid, :normal)
      receive do: ({:DOWN, ^ref, _, _, _} -> :ok)
    end) =~ ~r"""
