<?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: C program Kills cron daemon in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/c-program-kills-cron-daemon/m-p/4985114#M420718</link>
    <description>Do the setsid() that will fix you although to absolutely, properly do this you should:&lt;BR /&gt;&lt;BR /&gt;int main(int argc, char *argv[])&lt;BR /&gt;int cc = 0;&lt;BR /&gt;pid_t pid = 0;&lt;BR /&gt;{&lt;BR /&gt;  pid = fork();&lt;BR /&gt;  if (pid == 0)&lt;BR /&gt;    { /* child process */&lt;BR /&gt;      setsid();&lt;BR /&gt;      chdir("/"); /* so that filesystems can umount */&lt;BR /&gt;      /* Now your real work goes here */&lt;BR /&gt;      exit(cc);&lt;BR /&gt;    }&lt;BR /&gt;  else&lt;BR /&gt;    { /* parent process; just exit */&lt;BR /&gt;      exit(cc);&lt;BR /&gt;    }&lt;BR /&gt;} /* main */&lt;BR /&gt;    &lt;BR /&gt;if you fork() and then do the setsid(), you are assurred of setting up a new process group so your kill(0,SIGXXX) will not clobber cron.&lt;BR /&gt;</description>
    <pubDate>Tue, 13 Jun 2006 15:45:45 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2006-06-13T15:45:45Z</dc:date>
    <item>
      <title>C program Kills cron daemon</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-program-kills-cron-daemon/m-p/4985109#M420713</link>
      <description>I have a program that creates child processes.  To ensure that these processes are closed when the parent stops execution I am trapping SIGINT, SIGTERM and SIGQUIT.  When either of these 3 signals are received I send a kill(0, SIGKILL) to stop any lingering child processes.  Along with any child process the cron daemon consitantly goes down with them.  Despite the obvious solution of stop running this program as root, which should not have happend and has already been remedied, why is this kill going after the cron.  Shouldn't the 0 only send a SIGKILL to childs of like PID to the parent.  The program is started as a daemon and has the init parent PID of 1.  If the problem were that the parent PID is 1 then I would think I would see many more processes die then just the cron daemon everytime.  Any help on this subject would be appreciated.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance&lt;BR /&gt;&lt;BR /&gt;-Mike</description>
      <pubDate>Tue, 13 Jun 2006 13:36:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-program-kills-cron-daemon/m-p/4985109#M420713</guid>
      <dc:creator>Sarcom IS</dc:creator>
      <dc:date>2006-06-13T13:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: C program Kills cron daemon</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-program-kills-cron-daemon/m-p/4985110#M420714</link>
      <description>Shalom Mike,&lt;BR /&gt;&lt;BR /&gt;I would have to see your code to answer the question.&lt;BR /&gt;&lt;BR /&gt;I'm betting though its bad code.&lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Tue, 13 Jun 2006 13:38:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-program-kills-cron-daemon/m-p/4985110#M420714</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2006-06-13T13:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: C program Kills cron daemon</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-program-kills-cron-daemon/m-p/4985111#M420715</link>
      <description>First of all pull out a baseball bat and hit yourself over the head with it. Only as an absolute last resort should you send a SIGKILL (kill -9) to a process. Start with the kinder, gentler SIGTERM, then iSIGQUIT, SIGHUP, then SIGINT, then SIGSEGV (which is almost as sure a kill as SIGKILL) and finally SIGKILL. You should send a kill(0,pid) to each process to see if the pid is still valid before escalating the level of the signal. &lt;BR /&gt;&lt;BR /&gt;Your fundamental error was not immediately doing a setsid() before spawning any child processes so that a new process group is set up. It is then safe to do your kill(0,SIGTERM). The setsid() should occur very early in your cron'ed program. Man setsid for details.</description>
      <pubDate>Tue, 13 Jun 2006 14:00:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-program-kills-cron-daemon/m-p/4985111#M420715</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-06-13T14:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: C program Kills cron daemon</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-program-kills-cron-daemon/m-p/4985112#M420716</link>
      <description>Yes the SIGKILL should only be used as a last resort and certainly never placed within a program.&lt;BR /&gt;The program was called from a start script, executed by the cron, and even though the PPID is now 1 because the script that started it has finished, the program is still tied to the cron?  If the cron goes down say 70% of the time the program in question receives an interrupt, why isn't the cron dying the other 30% of the time?</description>
      <pubDate>Tue, 13 Jun 2006 14:44:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-program-kills-cron-daemon/m-p/4985112#M420716</guid>
      <dc:creator>Sarcom IS</dc:creator>
      <dc:date>2006-06-13T14:44:35Z</dc:date>
    </item>
    <item>
      <title>Re: C program Kills cron daemon</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-program-kills-cron-daemon/m-p/4985113#M420717</link>
      <description>&lt;BR /&gt;The issue appears to be similar to one I resolved year back when we had a security program that attempted to kill lingering child processes. Unfortunately, the PPID was 1, which KILLED every process with a PPID of 1.&lt;BR /&gt;&lt;BR /&gt;cron's ppid is 1&lt;BR /&gt;&lt;BR /&gt;It's your code. You should not kill processes with a PPID = 0 or 1. If a parent dies, the child gets assigned to init, hence ppid=1!&lt;BR /&gt;&lt;BR /&gt;Find a better way to locate and kill the actually related processes.&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry d brown jr</description>
      <pubDate>Tue, 13 Jun 2006 15:06:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-program-kills-cron-daemon/m-p/4985113#M420717</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2006-06-13T15:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: C program Kills cron daemon</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-program-kills-cron-daemon/m-p/4985114#M420718</link>
      <description>Do the setsid() that will fix you although to absolutely, properly do this you should:&lt;BR /&gt;&lt;BR /&gt;int main(int argc, char *argv[])&lt;BR /&gt;int cc = 0;&lt;BR /&gt;pid_t pid = 0;&lt;BR /&gt;{&lt;BR /&gt;  pid = fork();&lt;BR /&gt;  if (pid == 0)&lt;BR /&gt;    { /* child process */&lt;BR /&gt;      setsid();&lt;BR /&gt;      chdir("/"); /* so that filesystems can umount */&lt;BR /&gt;      /* Now your real work goes here */&lt;BR /&gt;      exit(cc);&lt;BR /&gt;    }&lt;BR /&gt;  else&lt;BR /&gt;    { /* parent process; just exit */&lt;BR /&gt;      exit(cc);&lt;BR /&gt;    }&lt;BR /&gt;} /* main */&lt;BR /&gt;    &lt;BR /&gt;if you fork() and then do the setsid(), you are assurred of setting up a new process group so your kill(0,SIGXXX) will not clobber cron.&lt;BR /&gt;</description>
      <pubDate>Tue, 13 Jun 2006 15:45:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-program-kills-cron-daemon/m-p/4985114#M420718</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-06-13T15:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: C program Kills cron daemon</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/c-program-kills-cron-daemon/m-p/4985115#M420719</link>
      <description>Thank you all for your responses.</description>
      <pubDate>Fri, 16 Jun 2006 11:27:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/c-program-kills-cron-daemon/m-p/4985115#M420719</guid>
      <dc:creator>Sarcom IS</dc:creator>
      <dc:date>2006-06-16T11:27:41Z</dc:date>
    </item>
  </channel>
</rss>

