[RESOLVED] bug in FpWait? lazarus / 32-Linux ---------------------------------------------------------------------- robert rozee · 2023-06-05 15:59 does the below behavior seem odd? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; uses SysUtils, BaseUnix; var L:longint; begin  if FpFork=0 then begin               // *** child process ***                     L:=90;                     writeln('child process sent ', IntToHex(L, 4));                     halt(L)                   end              else begin               // *** parent process ***                     FpWait(L);                     writeln('parent process got ', IntToHex(L, 4))                   endend. Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i user@DH61BE:~/pascal/tests/test 209 (FpFork)$ ./project1 child process sent 005Aparent process got 5A00user@DH61BE:~/pascal/tests/test 209 (FpFork)$ FpWait seems to return the exit code shifted left by 8 bits. linux mint 21.1, kernel: 5.19.0-43-generic, although this shouldn't matter. cheers, rob   :-) ---------------------------------------------------------------------- marcov · 2023-06-05 16:28 This is afaik normal behaviour for wait(2). IRC there is a wrapper called (fp)waitprocess() ---------------------------------------------------------------------- PascalDragon · 2023-06-05 19:30 Quote from: robert rozee on June 05, 2023, 05:59:20 pmFpWait seems to return the exit code shifted left by 8 bits. linux mint 21.1, kernel: 5.19.0-43-generic, although this shouldn't matter. FpWait() is simply a wrapper around POSIX wait(), so it's documentation applies, thus you need to use the wexitstatus() function from the BaseUnix unit. ---------------------------------------------------------------------- robert rozee · 2023-06-06 11:22 Quote from: PascalDragon on June 05, 2023, 09:30:19 pmyou need to use the wexitstatus() function from the BaseUnix unit aha... you are right! the following modification produces the desired result: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i             else begin               // *** parent process ***                   FpWait(L);                     L:=wexitStatus(L);                   writeln('parent process got ', IntToHex(L, 4))                   end with the prototype "Function  wexitStatus  (Status : cInt): cInt;" given in /usr/share/fpcsrc/3.2.2/rtl/unix/bunxovlh.inc and the function's source in /usr/share/fpcsrc/3.2.2/rtl/linux/osmacro.inc: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function wexitstatus(status : cint): cint;begin wexitstatus:=(status and $FF00) shr 8;end; it would be handy if the help for FpWait made reference to using wexitStatus to decode the stat_loc parameter passed back. is there any place to suggest changes/additions like this to the FPC documentation? cheers, rob   :-) ---------------------------------------------------------------------- dsiders · 2023-06-06 15:21 Quote from: robert rozee on June 06, 2023, 01:22:35 pm it would be handy if the help for FpWait made reference to using wexitStatus to decode the stat_loc parameter passed back. is there any place to suggest changes/additions like this to the FPC documentation? https://gitlab.com/freepascal.org/fpc/documentation/-/issues ---------------------------------------------------------------------- PascalDragon · 2023-06-06 19:50 Quote from: robert rozee on June 06, 2023, 01:22:35 pmit would be handy if the help for FpWait made reference to using wexitStatus to decode the stat_loc parameter passed back. is there any place to suggest changes/additions like this to the FPC documentation? We don't document operating system functions. Our modus operandi for these is to refer you (outside of our own documentation) to the documentation of the operating system. That's why I linked a man page above. ---------------------------------------------------------------------- robert rozee · 2023-06-08 08:10 Quote from: PascalDragon on June 06, 2023, 09:50:06 pmWe don't document operating system functions. Our modus operandi for these is to refer you (outside of our own documentation) to the documentation of the operating system. That's why I linked a man page above. while that is cetainly a noble and pure philosophical stance to take, the practicality is that for many users of FPC they will fail to discover the link between FpWait and wexitStatus. instead, they will assume that something in FPC is broken, or worse still fail to notice that the value of stat_loc (for linux) is the exitcode multiplied by 0x100. for the cost of but a ha'porth of tar, one could add to the help page for FpWait the single sentence: "if wifexited(stat_loc) returns true then wexitStatus(stat_loc) extracts the child's exitcode from stat_loc." sometimes pragmatism should override philosophical purity. cheers, rob   :-) ---------------------------------------------------------------------- PascalDragon · 2023-06-08 10:34 I just saw that we do have documentation for FpWait, so feel free to file a bug against the documentation to have that improved. ---------------------------------------------------------------------- robert rozee · 2023-06-08 11:04 tried creating a gitlab account, it emailed me a 'verification' number but there is nowhere to enter it. refused to let me log in using the details i'd supplied, and refuses to let me redo the registration from start. a fail. if anyone else wants to submit a 'bug against the documentation' of FpWait, to add the one line of text i suggested, please feel free to do so. cheers, rob   :-)