diff --git a/src/other/fork_test.s b/src/other/fork_test.s index b7169ea..9d76159 100644 --- a/src/other/fork_test.s +++ b/src/other/fork_test.s @@ -7,14 +7,33 @@ main: child: lac d1 sys write; childmsg; 3 + sys smes sys exit parent: + dac pid " save the childs pid lac d1 sys write; parentmsg; 4 + + sys rmes " wait for the child to exit + sad pid " did we get the same pid back? + jmp ok + +wrong: + lac d1 + sys write; badpid; 4 + sys exit + +ok: + lac d1 + sys write; goodpid; 4 sys exit d1: 1 " stdout fd +pid: 0 " child's pid parentmsg: ; ; ; 012000 childmsg: ; ; ; ; ; ; ; ; 012000 diff --git a/tools/a7out b/tools/a7out index 5885b61..381434a 100755 --- a/tools/a7out +++ b/tools/a7out @@ -537,6 +537,8 @@ sub cal { 17 => \&sys_chdir, 18 => \&sys_chmod, 19 => \&sys_chown, + 27 => \&sys_rmes, + 28 => \&sys_smes, 29 => \&sys_fork, ); @@ -551,7 +553,7 @@ sub cal { # Exit system call sub sys_exit { - dprintf("exit system call\n"); + dprintf("exit system call, pid %06o\n", $$); exit(0); } @@ -568,13 +570,35 @@ sub sys_fork { # Fork and get the child's process-id back, or zero if we are the child my $pid= fork(); - $AC= $pid; + $AC= $pid & MAXINT; + dprintf( "fork, got id %06o\n", $AC); # The parent returns back to PC+1, the child returns to PC+2 $PC += ($pid) ? 1 : 2; return; } +# Smes system call. Because we fake rmes with wait(), +# there is no need for sms. When the child does +# sys exit, that's going to wake wait() up and do the +# rmes anyway. +sub sys_smes { + # For now, do nothing + dprintf("smes system call\n"); + $PC += 1; + return; +} + +# Rmes system call. We simply call wait and +# return the process-id in AC +sub sys_rmes { + my $pid= wait(); + dprintf("rmes system call, got pid $pid\n"); + $AC= $pid & MAXINT; + $PC += 1; + return; +} + # Close system call sub sys_close {