MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / EndProcess

Function EndProcess

Kernel/src/arch/x86_64/scheduler.cpp:316–435  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

314 }
315
316 void EndProcess(process_t* process){
317 asm("sti");
318 while(process->children.get_length())
319 EndProcess(process->children.get_front());
320
321 CPU* cpu = GetCPULocal();
322 for(unsigned i = 0; i < process->threads.get_length(); i++){
323 thread_t* thread = process->threads[i];
324 if(thread != cpu->currentThread && thread){
325 thread->state = ThreadStateZombie;
326 acquireLock(&thread->lock); // Make sure we acquire a lock on all threads to ensure that they are not in a syscall and are not retaining a lock
327 }
328 }
329
330 if(process->parent){
331 process->parent->children.remove(process);
332 }
333
334 processes->remove(process);
335
336 for(thread_t* t : process->blocking){
337 UnblockThread(t);
338 }
339
340 for(unsigned i = 0; i < process->threads.get_length(); i++){
341 thread_t* thread = process->threads[i];
342
343 for(List<thread_t*>* queue : thread->waiting){
344 queue->remove(thread);
345 }
346
347 process->threads[i]->waiting.clear();
348
349 thread->state = ThreadStateBlocked;
350 thread->timeSlice = thread->timeSliceDefault = 0;
351 }
352
353 for(unsigned i = 0; i < process->fileDescriptors.get_length(); i++){
354 if(process->fileDescriptors[i]){
355 fs::Close(process->fileDescriptors[i]);
356 }
357 }
358
359 acquireLock(&cpu->runQueueLock);
360 asm("cli");
361
362 for(unsigned j = 0; j < cpu->runQueue->get_length(); j++){
363 if(cpu->runQueue->get_at(j)->parent == process) cpu->runQueue->remove_at(j);
364 }
365
366 for(fs_fd_t* fd : process->fileDescriptors){
367 if(fd && fd->node)
368 fd->node->Close();
369 }
370 process->fileDescriptors.clear();
371
372 for(unsigned i = 0; i < SMP::processorCount; i++){
373 if(i == cpu->id) continue; // Is current processor?

Callers 4

KernelProcessFunction · 0.85
isr_handlerFunction · 0.85
SysExitFunction · 0.85
PageFaultHandlerFunction · 0.85

Calls 15

GetCPULocalFunction · 0.85
UnblockThreadFunction · 0.85
SendIPIFunction · 0.85
Free4KPagesFunction · 0.85
DestroyAddressSpaceFunction · 0.85
kfreeFunction · 0.85
ScheduleFunction · 0.85
get_frontMethod · 0.80
get_atMethod · 0.80
~ListMethod · 0.80
CloseFunction · 0.50
get_lengthMethod · 0.45

Tested by

no test coverage detected