<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Parent and Child issue with C programming in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/parent-and-child-issue-with-c-programming/m-p/4912261#M103863</link>
    <description>&lt;BR /&gt;Henry,&lt;BR /&gt;&lt;BR /&gt;Just before the fork(), you can also do the following:&lt;BR /&gt;&lt;BR /&gt;signal( SIGCHLD, SIG_IGN );&lt;BR /&gt;&lt;BR /&gt;(be sure to #include &lt;SIGNAL.H&gt; at the top of your program)&lt;BR /&gt;&lt;BR /&gt;This will tell the parent process to ignore a stop or termination signal of a child.  This will further ensure that the child is independent from the parent.&lt;BR /&gt;&lt;BR /&gt;-- Tom&lt;BR /&gt;&lt;BR /&gt;&lt;/SIGNAL.H&gt;</description>
    <pubDate>Wed, 13 Jul 2005 07:58:24 GMT</pubDate>
    <dc:creator>Tom Schroll</dc:creator>
    <dc:date>2005-07-13T07:58:24Z</dc:date>
    <item>
      <title>Parent and Child issue with C programming</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parent-and-child-issue-with-c-programming/m-p/4912259#M103861</link>
      <description>Hi Guys,&lt;BR /&gt;&lt;BR /&gt;  I got some queries regarding C. Say I run a program A and it fork a child process B. How can I ensure B continue to run even after A process finished, i.e. make process B independent of its parent. Possible?&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Henry</description>
      <pubDate>Wed, 13 Jul 2005 02:42:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parent-and-child-issue-with-c-programming/m-p/4912259#M103861</guid>
      <dc:creator>Henry Chua</dc:creator>
      <dc:date>2005-07-13T02:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: Parent and Child issue with C programming</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parent-and-child-issue-with-c-programming/m-p/4912260#M103862</link>
      <description>When process A forks a process B, the process&lt;BR /&gt;B runs independent of the parent (ofcourse, it&lt;BR /&gt;might inherit some of the properties of the&lt;BR /&gt;parent during it's creation). You don't have to&lt;BR /&gt;do anything to make it "independent". If &lt;BR /&gt;process A dies, process B will continue to &lt;BR /&gt;run with "init" process (pid = 1) as the new &lt;BR /&gt;parent of the process B.&lt;BR /&gt;&lt;BR /&gt;- Biswajit&lt;BR /&gt;</description>
      <pubDate>Wed, 13 Jul 2005 03:22:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parent-and-child-issue-with-c-programming/m-p/4912260#M103862</guid>
      <dc:creator>Biswajit Tripathy</dc:creator>
      <dc:date>2005-07-13T03:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: Parent and Child issue with C programming</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parent-and-child-issue-with-c-programming/m-p/4912261#M103863</link>
      <description>&lt;BR /&gt;Henry,&lt;BR /&gt;&lt;BR /&gt;Just before the fork(), you can also do the following:&lt;BR /&gt;&lt;BR /&gt;signal( SIGCHLD, SIG_IGN );&lt;BR /&gt;&lt;BR /&gt;(be sure to #include &lt;SIGNAL.H&gt; at the top of your program)&lt;BR /&gt;&lt;BR /&gt;This will tell the parent process to ignore a stop or termination signal of a child.  This will further ensure that the child is independent from the parent.&lt;BR /&gt;&lt;BR /&gt;-- Tom&lt;BR /&gt;&lt;BR /&gt;&lt;/SIGNAL.H&gt;</description>
      <pubDate>Wed, 13 Jul 2005 07:58:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parent-and-child-issue-with-c-programming/m-p/4912261#M103863</guid>
      <dc:creator>Tom Schroll</dc:creator>
      <dc:date>2005-07-13T07:58:24Z</dc:date>
    </item>
    <item>
      <title>Re: Parent and Child issue with C programming</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parent-and-child-issue-with-c-programming/m-p/4912262#M103864</link>
      <description>Because it sounds like you are setting up a daemon (in which it is very common to fork() and let the parent die), you should also make a call to setsid() in the child  immediately after doing the fork(). This detaches the calling process from the parent and makes it a process group leader.</description>
      <pubDate>Wed, 13 Jul 2005 08:11:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parent-and-child-issue-with-c-programming/m-p/4912262#M103864</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-07-13T08:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: Parent and Child issue with C programming</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parent-and-child-issue-with-c-programming/m-p/4912263#M103865</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I prefer this interface:&lt;BR /&gt;&lt;BR /&gt;#include &lt;SIGNAL.H&gt;&lt;BR /&gt;&lt;BR /&gt;sigignore(SIGCHLD);&lt;BR /&gt;&lt;BR /&gt;This will prevent the OS from creating zombie processes from children, which have finished but 'think' that the parent process might want to known their exit status.&lt;BR /&gt;&lt;BR /&gt;mfG Peter&lt;/SIGNAL.H&gt;</description>
      <pubDate>Wed, 13 Jul 2005 08:27:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parent-and-child-issue-with-c-programming/m-p/4912263#M103865</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2005-07-13T08:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Parent and Child issue with C programming</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parent-and-child-issue-with-c-programming/m-p/4912264#M103866</link>
      <description>Hi Guys,&lt;BR /&gt;&lt;BR /&gt;  Say I want to use parent A to call a process B, B will be waiting an input signal from another program, but A need to terminal straight after call B. Can I write the program as such?&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;UNISTD.H&gt;&lt;BR /&gt;#include &lt;SYS&gt;&lt;BR /&gt;#include &lt;SYS&gt;&lt;BR /&gt;#include &lt;SIGNAL.H&gt;&lt;BR /&gt;&lt;BR /&gt;#define CHILD "/users/demo/demo/henry/program/chprog"&lt;BR /&gt;int&lt;BR /&gt;main()&lt;BR /&gt;{&lt;BR /&gt;        pid_t pid;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;        if (access (CHILD, 01) == 0)&lt;BR /&gt;        {&lt;BR /&gt;                printf(" File Not found!!");&lt;BR /&gt;        }&lt;BR /&gt;        signal(SIGCHLD, SIG_IGN);&lt;BR /&gt;        if ((pid=fork()) == 0)&lt;BR /&gt;                execlp( CHILD,CHILD,NULL);&lt;BR /&gt;&lt;BR /&gt;        else if (pid &amp;gt; 0)&lt;BR /&gt;                wait(0);&lt;BR /&gt;&lt;BR /&gt;        exit(0);&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;/SIGNAL.H&gt;&lt;/SYS&gt;&lt;/SYS&gt;&lt;/UNISTD.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Wed, 13 Jul 2005 18:16:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parent-and-child-issue-with-c-programming/m-p/4912264#M103866</guid>
      <dc:creator>Henry Chua</dc:creator>
      <dc:date>2005-07-13T18:16:58Z</dc:date>
    </item>
    <item>
      <title>Re: Parent and Child issue with C programming</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parent-and-child-issue-with-c-programming/m-p/4912265#M103867</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I usually use this type of pseudocode:&lt;BR /&gt;&lt;BR /&gt;if (! (pid=fork))&lt;BR /&gt;{ /* child */&lt;BR /&gt;  ...&lt;BR /&gt;  execXX(...);&lt;BR /&gt;  /* code for failed exec() follows */&lt;BR /&gt;  ...&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;/* code for parent follows, e.g. wait(), alarm(),.. */</description>
      <pubDate>Thu, 14 Jul 2005 03:09:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parent-and-child-issue-with-c-programming/m-p/4912265#M103867</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2005-07-14T03:09:48Z</dc:date>
    </item>
    <item>
      <title>Re: Parent and Child issue with C programming</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parent-and-child-issue-with-c-programming/m-p/4912266#M103868</link>
      <description>&lt;BR /&gt;According to the wait(2) man page, the behavior of wait() is affected if the SIGCHLD signal is set to SIG_IGN.  So why are you using wait() in your example?  You will not need it if the parent reads input interactively after forking.  Could you please describe what you are trying to do?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Also, here is another example of a code snip that is readable to a programmer who may be trying to maintain the code later:&lt;BR /&gt;&lt;BR /&gt;    signal( SIGCHLD, SIG_IGN );&lt;BR /&gt;&lt;BR /&gt;    /* Lets become a daemon now. */&lt;BR /&gt;    switch( fork() )&lt;BR /&gt;    {&lt;BR /&gt;        case -1: /* fork() failed */&lt;BR /&gt;            fprintf( stderr, "ERROR: fork failed (%s)\n\r", strerror(errno) );&lt;BR /&gt;            exit( 1 );&lt;BR /&gt;            break;&lt;BR /&gt;&lt;BR /&gt;        case 0: /* child process */&lt;BR /&gt;            startChild();&lt;BR /&gt;            break;&lt;BR /&gt;            &lt;BR /&gt;        default: /* parent process */&lt;BR /&gt;            break;&lt;BR /&gt;    }&lt;BR /&gt;    /* In parent process, do whatever else you need here. */&lt;BR /&gt;    exit( 0 );&lt;BR /&gt;}       &lt;BR /&gt;&lt;BR /&gt;(the formatting is messed up by the forum, so please see attached file for a formatted version)&lt;BR /&gt;&lt;BR /&gt;-- Tom</description>
      <pubDate>Thu, 14 Jul 2005 14:27:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parent-and-child-issue-with-c-programming/m-p/4912266#M103868</guid>
      <dc:creator>Tom Schroll</dc:creator>
      <dc:date>2005-07-14T14:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: Parent and Child issue with C programming</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parent-and-child-issue-with-c-programming/m-p/4912267#M103869</link>
      <description>Thanks Tom.. your advise works great!!</description>
      <pubDate>Mon, 01 Aug 2005 03:16:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parent-and-child-issue-with-c-programming/m-p/4912267#M103869</guid>
      <dc:creator>Henry Chua</dc:creator>
      <dc:date>2005-08-01T03:16:35Z</dc:date>
    </item>
  </channel>
</rss>

