+ 3
How to solve the below question?
Give all the possible display results obtained by running the below program?? Assume that the parent id Pid = 100; /* If you can explain how fork() works with + and * */ int main(){ int x; x = ( fork() + fork() ) * fork() ); print("%d", x); }
5 Respuestas
+ 7
Im not an expert, but fork would create a copied unix process which executee from fork call (same happen for original parent process) return 0 to child process and process PID to parent process. In your case, i think, this happen at (fork() + fork()) * fork():
- at first fork call, A process (the main process) create a child process B
-at second fork call, either in A and B will forked other child 2 processes (C and D)
- at third fork call, other 4 processes will be forked from A, B, C and D (E,F,G,H)
at end you will have 8 processes (in practice 2^n where n is fork calls count). Anyway, about the x value, all depends on which process you want see... In main process (the original A) x will be (100+100)*100=20000 while in forked processes all depends by own PID and from parent process.
Anyway, im not sure, maybe someone more expert will help you better
+ 4
Try Solve yourself
+ 3
KrOW thank you for your reply
+ 3
👍👍👍
+ 2
I don't know how fork() works with the two operators "+" and "*"