How does this code execute more than one case of the if - else statements?How does the kernel know which file...

Passport - tiny rip on the edge of my passport page

Examples where "thin + thin = nice and thick"

Is mountain bike good for long distances?

Why did Boris Johnson call for new elections?

Is future tense in English really a myth?

How is the phase of 120V AC established in a North American home?

How do draw effects during the discard phase work?

Did the Byzantines ever attempt to move their capital to Rome?

Why are some hotels asking you to book through Booking.com instead of matching the price at the front desk?

How to improvise or make pot grip / pot handle

What does "先が気になる" mean?

Contractor cut joist hangers to make them fit

How many attacks exactly do I get combining Dual Wielder feat with Two-Weapon Fighting style?

Poor management handling of recent sickness and how to approach my return?

GFCI No Equipment Ground not testing

Does the word voltage exist in academic engineering?

What is the purpose of the rotating plate in front of the lock?

How do I play this harmonic? (Guitar)

Project Euler Problem 45

How can I hint that my character isn't real?

Gapping comma in a list

What quests do you need to stop at before you make an enemy of a faction for each faction?

Why are there no wireless switches?

How do German speakers decide what should be on the left side of the verb?



How does this code execute more than one case of the if - else statements?


How does the kernel know which file descriptor to write data to after fork() in a concurrent server?What is the exact function of this malicious bash one-liner?How exactly does the typical shell “fork bomb” call itself twice?How does a parent process know the process IDs of the child processes it started?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
printf("hello world (pid:%d)n", (int) getpid());
int rc = fork();
if (rc < 0) {
// fork failed
fprintf(stderr, "fork failedn");
exit(1);
}
elseif(rc==0){
// child (new process)
printf("hello, I am child (pid:%d)n", (int) getpid());
}
else {
// parent goes down this path (main)
printf("hello, I am parent of %d (pid:%d)n",
rc, (int) getpid());

}
return 0;

}


Output:



prompt> ./p1
hello world (pid:29146)
hello, I am parent of 29147 (pid:29146)
hello, I am child (pid:29147)
prompt>


Either "hello, I am parent" or "hello, I am child" should be given as output, not both.










share|improve this question









New contributor



Dheeraj Reddy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




























    0















    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>

    int main(int argc, char *argv[]) {
    printf("hello world (pid:%d)n", (int) getpid());
    int rc = fork();
    if (rc < 0) {
    // fork failed
    fprintf(stderr, "fork failedn");
    exit(1);
    }
    elseif(rc==0){
    // child (new process)
    printf("hello, I am child (pid:%d)n", (int) getpid());
    }
    else {
    // parent goes down this path (main)
    printf("hello, I am parent of %d (pid:%d)n",
    rc, (int) getpid());

    }
    return 0;

    }


    Output:



    prompt> ./p1
    hello world (pid:29146)
    hello, I am parent of 29147 (pid:29146)
    hello, I am child (pid:29147)
    prompt>


    Either "hello, I am parent" or "hello, I am child" should be given as output, not both.










    share|improve this question









    New contributor



    Dheeraj Reddy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.
























      0












      0








      0








      #include <stdio.h>
      #include <stdlib.h>
      #include <unistd.h>

      int main(int argc, char *argv[]) {
      printf("hello world (pid:%d)n", (int) getpid());
      int rc = fork();
      if (rc < 0) {
      // fork failed
      fprintf(stderr, "fork failedn");
      exit(1);
      }
      elseif(rc==0){
      // child (new process)
      printf("hello, I am child (pid:%d)n", (int) getpid());
      }
      else {
      // parent goes down this path (main)
      printf("hello, I am parent of %d (pid:%d)n",
      rc, (int) getpid());

      }
      return 0;

      }


      Output:



      prompt> ./p1
      hello world (pid:29146)
      hello, I am parent of 29147 (pid:29146)
      hello, I am child (pid:29147)
      prompt>


      Either "hello, I am parent" or "hello, I am child" should be given as output, not both.










      share|improve this question









      New contributor



      Dheeraj Reddy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      #include <stdio.h>
      #include <stdlib.h>
      #include <unistd.h>

      int main(int argc, char *argv[]) {
      printf("hello world (pid:%d)n", (int) getpid());
      int rc = fork();
      if (rc < 0) {
      // fork failed
      fprintf(stderr, "fork failedn");
      exit(1);
      }
      elseif(rc==0){
      // child (new process)
      printf("hello, I am child (pid:%d)n", (int) getpid());
      }
      else {
      // parent goes down this path (main)
      printf("hello, I am parent of %d (pid:%d)n",
      rc, (int) getpid());

      }
      return 0;

      }


      Output:



      prompt> ./p1
      hello world (pid:29146)
      hello, I am parent of 29147 (pid:29146)
      hello, I am child (pid:29147)
      prompt>


      Either "hello, I am parent" or "hello, I am child" should be given as output, not both.







      fork






      share|improve this question









      New contributor



      Dheeraj Reddy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share|improve this question









      New contributor



      Dheeraj Reddy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share|improve this question




      share|improve this question








      edited 27 mins ago









      cas

      42.7k4 gold badges62 silver badges112 bronze badges




      42.7k4 gold badges62 silver badges112 bronze badges






      New contributor



      Dheeraj Reddy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      asked 30 mins ago









      Dheeraj ReddyDheeraj Reddy

      1




      1




      New contributor



      Dheeraj Reddy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      New contributor




      Dheeraj Reddy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.



























          0






          active

          oldest

          votes














          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });







          Dheeraj Reddy is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded
















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f539445%2fhow-does-this-code-execute-more-than-one-case-of-the-if-else-statements%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          Dheeraj Reddy is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded

















          Dheeraj Reddy is a new contributor. Be nice, and check out our Code of Conduct.













          Dheeraj Reddy is a new contributor. Be nice, and check out our Code of Conduct.












          Dheeraj Reddy is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f539445%2fhow-does-this-code-execute-more-than-one-case-of-the-if-else-statements%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

          Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

          Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...