if (!p) return;
if (p->pid == 0) return;
- /* Safety net: ensure process is not in any runqueue/sleep queue before freeing */
+ /* Safety net: ensure process is not in any runqueue/sleep/alarm queue before freeing */
rq_remove_if_queued(p);
sleep_queue_remove(p);
+ alarm_queue_remove(p);
if (p == ready_queue_head && p == ready_queue_tail) {
return;
if (sig <= 0 || sig >= PROCESS_MAX_SIG) return -EINVAL;
if (current_process && current_process->pid == pid && sig == SIG_KILL) {
+ process_close_all_files_locked(current_process);
process_exit_notify(128 + sig);
hal_cpu_enable_interrupts();
schedule();
/* We are in the child — exec immediately */
int rc = syscall_execve_impl(regs, path, argv, envp);
if (rc < 0) {
- /* execve failed — exit child */
+ /* execve failed — close FDs and exit child */
+ for (int _fd = 0; _fd < PROCESS_MAX_FILES; _fd++) {
+ if (current_process && current_process->files[_fd])
+ (void)fd_close(_fd);
+ }
process_exit_notify(127);
hal_cpu_enable_interrupts();
schedule();