es-shell icon indicating copy to clipboard operation
es-shell copied to clipboard

Missing pids in the result of %apids after fork

Open memreflect opened this issue 4 months ago • 0 comments

; {result 99} &
30172
; echo <=%apids
30172
; echo <=%apids
30172
; fork {}
; echo <=%apids

; echo <=wait
99
;

The underlying problem is that wait3()/wait() does not allow you to specify a process ID, so the ewait() function in es uses a loop to wait for processes until finally the matching process ID is returned by wait3()/wait(). Each of those waited-for processes are marked as dead by setting proc->alive = FALSE, but the processes still exist in es for $&wait to return the status before they get fully deallocated. Since %apids only returns processes that are alive, any processes that were marked dead until the correct process ID was returned by wait3()/wait() seem to disappear. So what happens is when fork {} gets executed, a fork occurs and es waits for that fork, marking any other processes along the way as dead.

Switching from wait3()/wait() to waitpid() as suggested in #117 would fix this. It would allow the process ID of a specific forked process to be waited upon without affecting the alive/dead status of other processes.

memreflect avatar Oct 06 '24 17:10 memreflect