Why do some programs' processes exist after forking a child, without the child starting a new process...












0














Here are some of the steps for creating a daemon process from a given process,




  • the given process exists soon after forking a child,


  • the child calls start a new session and also a new group, by setsid()



But I seem to find cases with only the first step without the second step:




  • in a login session under a desktop environment


  • in an interactive bash process.



What is the purpose of only having the first step without the second step?



Does it not want to create a daemon but something else?



Thanks.










share|improve this question





























    0














    Here are some of the steps for creating a daemon process from a given process,




    • the given process exists soon after forking a child,


    • the child calls start a new session and also a new group, by setsid()



    But I seem to find cases with only the first step without the second step:




    • in a login session under a desktop environment


    • in an interactive bash process.



    What is the purpose of only having the first step without the second step?



    Does it not want to create a daemon but something else?



    Thanks.










    share|improve this question



























      0












      0








      0


      1





      Here are some of the steps for creating a daemon process from a given process,




      • the given process exists soon after forking a child,


      • the child calls start a new session and also a new group, by setsid()



      But I seem to find cases with only the first step without the second step:




      • in a login session under a desktop environment


      • in an interactive bash process.



      What is the purpose of only having the first step without the second step?



      Does it not want to create a daemon but something else?



      Thanks.










      share|improve this question















      Here are some of the steps for creating a daemon process from a given process,




      • the given process exists soon after forking a child,


      • the child calls start a new session and also a new group, by setsid()



      But I seem to find cases with only the first step without the second step:




      • in a login session under a desktop environment


      • in an interactive bash process.



      What is the purpose of only having the first step without the second step?



      Does it not want to create a daemon but something else?



      Thanks.







      linux bash process session






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 27 '18 at 22:10







      Tim

















      asked Dec 27 '18 at 17:46









      TimTim

      26.3k74246455




      26.3k74246455






















          1 Answer
          1






          active

          oldest

          votes


















          0














          The purpose, on high level, is best seen in the bash example that you gave. When, in an interactive bash shell, a normal user types ls, what happens is




          • Bash forks

          • the child process execs ls

          • when ls is finished, the child process ends


          It would be silly to daemonize ls, because (in general) it ends very quickly.



          Furthermore, it would also be strange is all processes that are forked from a shell would do a setuid(). You would then not be able to run a shell as a normal user.



          Do not take the specifics of daemons as the general rule for the use of fork/exec.






          share|improve this answer























          • Thanks, I didn't ask how a shell executes an external command in general.
            – Tim
            Dec 27 '18 at 22:09












          • The point is in the last sentence: you seem to take the process of daemonisation as the norm.
            – Ljm Dullaart
            Dec 27 '18 at 23:18










          • I didn't. Please reread my post.
            – Tim
            Dec 29 '18 at 2:49










          • "Does it not want to create a daemon but something else?" The answer then is "something else". I also noticed that you changed setuid() in your question to setsid(), which makes my remark about setuid() no longer applicable.
            – Ljm Dullaart
            Dec 29 '18 at 13:26










          • That's my typo.
            – Tim
            Dec 29 '18 at 13:28











          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/3.0/"u003ecc by-sa 3.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
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491174%2fwhy-do-some-programs-processes-exist-after-forking-a-child-without-the-child-s%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          The purpose, on high level, is best seen in the bash example that you gave. When, in an interactive bash shell, a normal user types ls, what happens is




          • Bash forks

          • the child process execs ls

          • when ls is finished, the child process ends


          It would be silly to daemonize ls, because (in general) it ends very quickly.



          Furthermore, it would also be strange is all processes that are forked from a shell would do a setuid(). You would then not be able to run a shell as a normal user.



          Do not take the specifics of daemons as the general rule for the use of fork/exec.






          share|improve this answer























          • Thanks, I didn't ask how a shell executes an external command in general.
            – Tim
            Dec 27 '18 at 22:09












          • The point is in the last sentence: you seem to take the process of daemonisation as the norm.
            – Ljm Dullaart
            Dec 27 '18 at 23:18










          • I didn't. Please reread my post.
            – Tim
            Dec 29 '18 at 2:49










          • "Does it not want to create a daemon but something else?" The answer then is "something else". I also noticed that you changed setuid() in your question to setsid(), which makes my remark about setuid() no longer applicable.
            – Ljm Dullaart
            Dec 29 '18 at 13:26










          • That's my typo.
            – Tim
            Dec 29 '18 at 13:28
















          0














          The purpose, on high level, is best seen in the bash example that you gave. When, in an interactive bash shell, a normal user types ls, what happens is




          • Bash forks

          • the child process execs ls

          • when ls is finished, the child process ends


          It would be silly to daemonize ls, because (in general) it ends very quickly.



          Furthermore, it would also be strange is all processes that are forked from a shell would do a setuid(). You would then not be able to run a shell as a normal user.



          Do not take the specifics of daemons as the general rule for the use of fork/exec.






          share|improve this answer























          • Thanks, I didn't ask how a shell executes an external command in general.
            – Tim
            Dec 27 '18 at 22:09












          • The point is in the last sentence: you seem to take the process of daemonisation as the norm.
            – Ljm Dullaart
            Dec 27 '18 at 23:18










          • I didn't. Please reread my post.
            – Tim
            Dec 29 '18 at 2:49










          • "Does it not want to create a daemon but something else?" The answer then is "something else". I also noticed that you changed setuid() in your question to setsid(), which makes my remark about setuid() no longer applicable.
            – Ljm Dullaart
            Dec 29 '18 at 13:26










          • That's my typo.
            – Tim
            Dec 29 '18 at 13:28














          0












          0








          0






          The purpose, on high level, is best seen in the bash example that you gave. When, in an interactive bash shell, a normal user types ls, what happens is




          • Bash forks

          • the child process execs ls

          • when ls is finished, the child process ends


          It would be silly to daemonize ls, because (in general) it ends very quickly.



          Furthermore, it would also be strange is all processes that are forked from a shell would do a setuid(). You would then not be able to run a shell as a normal user.



          Do not take the specifics of daemons as the general rule for the use of fork/exec.






          share|improve this answer














          The purpose, on high level, is best seen in the bash example that you gave. When, in an interactive bash shell, a normal user types ls, what happens is




          • Bash forks

          • the child process execs ls

          • when ls is finished, the child process ends


          It would be silly to daemonize ls, because (in general) it ends very quickly.



          Furthermore, it would also be strange is all processes that are forked from a shell would do a setuid(). You would then not be able to run a shell as a normal user.



          Do not take the specifics of daemons as the general rule for the use of fork/exec.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 27 '18 at 19:04









          Tim

          26.3k74246455




          26.3k74246455










          answered Dec 27 '18 at 18:51









          Ljm DullaartLjm Dullaart

          58817




          58817












          • Thanks, I didn't ask how a shell executes an external command in general.
            – Tim
            Dec 27 '18 at 22:09












          • The point is in the last sentence: you seem to take the process of daemonisation as the norm.
            – Ljm Dullaart
            Dec 27 '18 at 23:18










          • I didn't. Please reread my post.
            – Tim
            Dec 29 '18 at 2:49










          • "Does it not want to create a daemon but something else?" The answer then is "something else". I also noticed that you changed setuid() in your question to setsid(), which makes my remark about setuid() no longer applicable.
            – Ljm Dullaart
            Dec 29 '18 at 13:26










          • That's my typo.
            – Tim
            Dec 29 '18 at 13:28


















          • Thanks, I didn't ask how a shell executes an external command in general.
            – Tim
            Dec 27 '18 at 22:09












          • The point is in the last sentence: you seem to take the process of daemonisation as the norm.
            – Ljm Dullaart
            Dec 27 '18 at 23:18










          • I didn't. Please reread my post.
            – Tim
            Dec 29 '18 at 2:49










          • "Does it not want to create a daemon but something else?" The answer then is "something else". I also noticed that you changed setuid() in your question to setsid(), which makes my remark about setuid() no longer applicable.
            – Ljm Dullaart
            Dec 29 '18 at 13:26










          • That's my typo.
            – Tim
            Dec 29 '18 at 13:28
















          Thanks, I didn't ask how a shell executes an external command in general.
          – Tim
          Dec 27 '18 at 22:09






          Thanks, I didn't ask how a shell executes an external command in general.
          – Tim
          Dec 27 '18 at 22:09














          The point is in the last sentence: you seem to take the process of daemonisation as the norm.
          – Ljm Dullaart
          Dec 27 '18 at 23:18




          The point is in the last sentence: you seem to take the process of daemonisation as the norm.
          – Ljm Dullaart
          Dec 27 '18 at 23:18












          I didn't. Please reread my post.
          – Tim
          Dec 29 '18 at 2:49




          I didn't. Please reread my post.
          – Tim
          Dec 29 '18 at 2:49












          "Does it not want to create a daemon but something else?" The answer then is "something else". I also noticed that you changed setuid() in your question to setsid(), which makes my remark about setuid() no longer applicable.
          – Ljm Dullaart
          Dec 29 '18 at 13:26




          "Does it not want to create a daemon but something else?" The answer then is "something else". I also noticed that you changed setuid() in your question to setsid(), which makes my remark about setuid() no longer applicable.
          – Ljm Dullaart
          Dec 29 '18 at 13:26












          That's my typo.
          – Tim
          Dec 29 '18 at 13:28




          That's my typo.
          – Tim
          Dec 29 '18 at 13:28


















          draft saved

          draft discarded




















































          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f491174%2fwhy-do-some-programs-processes-exist-after-forking-a-child-without-the-child-s%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

          Morgemoulin

          Scott Moir

          Souastre