diff --git a/kernel/exit.c b/kernel/exit.c
index 7127c15faf28c3a71e2facf9afc165078b604953..02f0a95cb55705f758a576b8eaf11f8c26f0fc02 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -790,6 +790,12 @@ fastcall NORET_TYPE void do_exit(long code)
 		panic("Attempted to kill init!");
 	if (tsk->io_context)
 		exit_io_context();
+
+	if (unlikely(current->ptrace & PT_TRACE_EXIT)) {
+		current->ptrace_message = code;
+		ptrace_notify((PTRACE_EVENT_EXIT << 8) | SIGTRAP);
+	}
+
 	tsk->flags |= PF_EXITING;
 	del_timer_sync(&tsk->real_timer);
 
@@ -798,11 +804,6 @@ fastcall NORET_TYPE void do_exit(long code)
 				current->comm, current->pid,
 				preempt_count());
 
-	if (unlikely(current->ptrace & PT_TRACE_EXIT)) {
-		current->ptrace_message = code;
-		ptrace_notify((PTRACE_EVENT_EXIT << 8) | SIGTRAP);
-	}
-
 	acct_update_integrals();
 	update_mem_hiwater();
 	group_dead = atomic_dec_and_test(&tsk->signal->live);