What I am trying to do is create a program that searches an array. In addition I am going to search different sections of the array with different processes. My question is, is their a way to set the exit status of a process to be the position of the value searched instead of the exit status returning 0?
Asked
Active
Viewed 39 times
0
-
1That would be a very bad idea. It would also limit you to very small arrays, since the exit status is usually only an 8 bit value. See e.g. [this question](https://stackoverflow.com/q/8082953/253056). – Paul R Nov 05 '19 at 17:52
-
Is it possible to do if so how would I alter the 8 bit value? – cLax Nov 05 '19 at 17:53
-
1You would just `return value;` from `main()`, but it seems fairly pointless and inappropriate to do this when there are much more suitable ways. – Paul R Nov 05 '19 at 17:55
-
1When you say `processes` , you mean you're forking right? if that's the case (and keeping in mind the first comment about it being a bad idea) can't you just do a `exit(pos)` inside the children? or did i really just miss the point of the question? A sample code would be really helpful. – mdaoud Nov 05 '19 at 17:59
-
1the `int` return code passed to [`exit`](http://man7.org/linux/man-pages/man3/exit.3.html) is ANDed with 0x0377, so unless your array position happens to be unchanged from `pos & 0x0377`, you won't get the correct position. – yano Nov 05 '19 at 18:04
-
yes I am using fork() – cLax Nov 05 '19 at 18:15