1 /*
2  * Copyright (c) 2025 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include "kernel_shell.h"
8 
9 #include <kernel_internal.h>
10 #include <zephyr/kernel.h>
11 #include <stdint.h>
12 #include <stdlib.h>
13 
cmd_kernel_thread_kill(const struct shell * sh,size_t argc,char ** argv)14 static int cmd_kernel_thread_kill(const struct shell *sh, size_t argc, char **argv)
15 {
16 	/* thread_id is converetd from hex to decimal */
17 	k_tid_t thread_id = (k_tid_t)strtoul(argv[1], NULL, 16);
18 
19 	if (!z_thread_is_valid(thread_id)) {
20 		shell_error(sh, "Thread ID %p is not valid", thread_id);
21 		return -EINVAL;
22 	}
23 
24 	/*Check if the thread ID is the shell thread */
25 	if (thread_id == k_current_get()) {
26 		shell_error(sh, "Error:Shell thread cannot be killed");
27 		return -EINVAL;
28 	}
29 
30 	k_thread_abort(thread_id);
31 
32 	shell_print(sh, "\n Thread %p killed", thread_id);
33 
34 	return 0;
35 }
36 
37 KERNEL_THREAD_CMD_ARG_ADD(kill, NULL, "kernel thread kill <thread_id>", cmd_kernel_thread_kill, 2,
38 			  0);
39