MCPcopy Create free account
hub / github.com/Singular/Singular / fork_process

Function fork_process

kernel/oswrapper/vspace.cc:426–454  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

424} // namespace internals
425
426pid_t fork_process() {
427 using namespace internals;
428 lock_metapage();
429 for (int p = 0; p < MAX_PROCESS; p++) {
430 if (vmem.metapage->process_info[p].pid == 0) {
431 pid_t pid = fork();
432 if (pid < 0) {
433 // error
434 return -1;
435 } else if (pid == 0) {
436 // child process
437 int parent = vmem.current_process;
438 vmem.current_process = p;
439 lock_metapage();
440 vmem.metapage->process_info[p].pid = getpid();
441 unlock_metapage();
442 send_signal(parent);
443 } else {
444 // parent process
445 unlock_metapage();
446 wait_signal();
447 // child has unlocked metapage, so we don't need to.
448 }
449 return pid;
450 }
451 }
452 unlock_metapage();
453 return -1;
454}
455
456void Semaphore::post() {
457 int wakeup = -1;

Callers 3

kVerify2Function · 0.85
id_ChineseRemainder_0Function · 0.85
id_Farey_0Function · 0.85

Calls 4

lock_metapageFunction · 0.85
unlock_metapageFunction · 0.85
send_signalFunction · 0.85
wait_signalFunction · 0.85

Tested by

no test coverage detected