0

I'm working on a project where i should build my own shell, the problem is i know the return value of a child process is a number containing a lot of information not just the exit status, and to get the exit status you shuld use the macro WEXITSTATUS, now i'm looking how i can convert a simple integer to the return value of a process in purpose to use WEXITSTATUS and get back that integer,

for example : i have the number 258, i want to do some bit wise shifting then use WEXITSTATUS to get 258, it's like i want to know the number that produce 258 when i use WEXITSTATUS.

Thank you !

REVERSI
  • 59
  • 5
  • 258 doesn't fit in one byte. – stark Dec 12 '20 at 12:52
  • [Per POSIX](https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_13), only the low-order 8 bits of any return value is acessible. 258 won't fit in 8 bits, so there is no number that can produce 258. POSIX does say "Note that these 8 bits are part of the **complete value** that is used to set the `si_status` member of the `siginfo_t` structure provided by `waitid()`", so `waitid()` is ***supposed to*** return the full `int` value returned from a process exit, but I'm pretty sure Linux is broken here and only returns the low 8 bits. – Andrew Henle Dec 12 '20 at 12:53
  • 2
    @stark: Oh, you kids. Back in the day, we had bigger bytes that could hold 258. In fact, the C standard still allows that. Why do you let manufacturers get away with giving you smaller bytes? You should protest. – Eric Postpischil Dec 12 '20 at 12:54
  • @EricPostpischil bytes should big enough to accommodate any number!!! That is my demand. – 0___________ Dec 12 '20 at 12:57
  • Bits are pretty limiting as well. When are we switching to base 3? – stark Dec 12 '20 at 12:59
  • Yes, Linux is broken here: [**How to get the full returned value of a child process?**](https://stackoverflow.com/questions/50982730/how-to-get-the-full-returned-value-of-a-child-process) – Andrew Henle Dec 12 '20 at 13:06
  • 2
    @stark [The sixties](https://en.wikipedia.org/wiki/Setun) were an interesting time. – Shawn Dec 12 '20 at 13:11
  • Consider using a pipe (close-on-exec pipes are excellent for passing the error if child process exec fails; the pipe end being closed by the kernel if the exec succeeds), or a POSIX realtime signal (`SIGRTMIN+0` to `SIGRTMAX-0`, inclusive) with `sigqueue()` before exiting. Realtime signals are queued, thus more reliable than the standard signals (but not as reliable as a pipe). – Glärbo Dec 12 '20 at 21:04

0 Answers0