Skip to content

Commit e564934

Browse files
committed
added process kill
1 parent 7a7e674 commit e564934

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

kernel/task/process/process.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "../../../mm/paging/paging.h"
1616
#include "../../../g-loader/g-loader.h"
1717
#include "../../../g-loader/elf/elf.h"
18+
#include "../task.h"
1819

1920
// #include "../../../kernel/kernel.h"
2021

@@ -300,4 +301,38 @@ void* process_free(void* base_addr){
300301

301302
return 0;
302303

304+
}
305+
306+
307+
int process_kill(struct process* _process){
308+
309+
if(_process == 0){
310+
return -ERR_INVARG;
311+
}
312+
313+
// free all data dynamically allocated by the process.
314+
for(int allocation = 0;allocation < PROCESS_MAX_PROCESS_MEM_ALLOCATIONS; allocation++){
315+
process_free(_process->mem_allocations[allocation]);
316+
}
317+
318+
// mark pid as free to use
319+
process_list[_process->pid] = 0;
320+
321+
// free the stack given to the process.
322+
kfree(_process->stack);
323+
324+
if(_process->file_type == PROCESS_ELF_FILE){
325+
gloader_close_elf(_process->elf_data);
326+
}else if(_process->file_type == PROCESS_BIN_FILE){
327+
kfree(_process->raw_data);
328+
}
329+
330+
// kill the task associated with the process.
331+
task_kill(_process->task);
332+
333+
kfree(_process);
334+
335+
return SUCCESS;
336+
337+
303338
}

kernel/task/process/process.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct process *process_new(const char *filename);
1616
struct process *process_current();
1717
void* process_malloc(uint32_t size);
1818
void* process_free(void* base_addr);
19+
int process_kill(struct process* _process);
1920

2021
void process_init();
2122

0 commit comments

Comments
 (0)