<?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: communication with background function in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320281#M187263</link>
    <description>hai,&lt;BR /&gt;&lt;BR /&gt; We can get the back ground running process with some debugging statements and results redirection to a common file.&lt;BR /&gt;&lt;BR /&gt; We can not use the environment variables in this situation,because client process can not change main process variables value.&lt;BR /&gt;&lt;BR /&gt; We cannot check the return type of backgroundly running process. It may be end at any time. &lt;BR /&gt;&lt;BR /&gt; The best way is to put the debug statements in the begin,during the operation and end of operation withit's PID and identifier like that.&lt;BR /&gt;&lt;BR /&gt; We can use pipe in the script to interact with the main process to know the completion of execution.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Muthukumar</description>
    <pubDate>Thu, 01 Jul 2004 08:25:05 GMT</pubDate>
    <dc:creator>Muthukumar_5</dc:creator>
    <dc:date>2004-07-01T08:25:05Z</dc:date>
    <item>
      <title>communication with background function</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320275#M187257</link>
      <description>&lt;BR /&gt;  I a script I define a function which I need to call in the background and at certain places check it's status and see if it's finished (without waiting for it); if it's finished I need to check it's return value and I also need to communicate with the main script via an environment variable (lateral effect) in which I put something; is this possible?&lt;BR /&gt;&lt;BR /&gt;  Thanks&lt;BR /&gt;</description>
      <pubDate>Thu, 01 Jul 2004 05:25:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320275#M187257</guid>
      <dc:creator>vtihu</dc:creator>
      <dc:date>2004-07-01T05:25:00Z</dc:date>
    </item>
    <item>
      <title>Re: communication with background function</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320276#M187258</link>
      <description>2 simple options I can think of: -&lt;BR /&gt;&lt;BR /&gt;1) Have your background script write status information etc to a temporary file, and your "checking" script monitor the contents of this file.&lt;BR /&gt;&lt;BR /&gt;2) Use a named pipes.  eg "mknod inpipe p", "mknod outpipe p".  Your script can then write to the outpipe file, and read from the inpipe file.&lt;BR /&gt;&lt;BR /&gt;Note that the second method will "need" a program on the end of the pipes, essentially "feeding" it, otherwise it'll just hang up when it reads/writes.&lt;BR /&gt;&lt;BR /&gt;Which option you use depends on what exactly you're trying to achieve.</description>
      <pubDate>Thu, 01 Jul 2004 05:50:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320276#M187258</guid>
      <dc:creator>Simon Hargrave</dc:creator>
      <dc:date>2004-07-01T05:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: communication with background function</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320277#M187259</link>
      <description>Simons solutions (above) make a good deal of sense to me.  Though to address the individual questions you have here I thought I'd offer some thoughts.&lt;BR /&gt; &lt;BR /&gt;The best way of running a script and checking to see if it's finished is to trap "SIGCHLD".  Your script will do something like &lt;BR /&gt; &lt;BR /&gt;trap "myfunction" 18&lt;BR /&gt; &lt;BR /&gt;When your child script exits, the function "myfunction" will be called.&lt;BR /&gt; &lt;BR /&gt;The way to check the exit status of a command you ran in the background would be to use "wait".  In the above example, you would put this in your "myfunction" function.  Wait expects a job number.  However, if your script only runs one other script in the background, the job number will probably be 1 .  So, in "myfunction" you would have "wait %1" and the exit status of that is the exit status of the job you ran in the background.&lt;BR /&gt; &lt;BR /&gt;You can not pass an environment variable to a parent.  You can however get your child script to print the value as in&lt;BR /&gt; &lt;BR /&gt;VARIABLE=`my-sub-script` &amp;amp;&lt;BR /&gt; &lt;BR /&gt;However, variable will probably have a carriage return followed by some job control output appended to it. You can strip that off though.&lt;BR /&gt; &lt;BR /&gt;These things combined might get you what you want.</description>
      <pubDate>Thu, 01 Jul 2004 06:04:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320277#M187259</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-07-01T06:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: communication with background function</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320278#M187260</link>
      <description>&lt;BR /&gt;  Simon: I thought about this file approach too but I prefer another way of solving this, more direct;&lt;BR /&gt;  Mark: very good the trap suggestion, at least theoretically, but first I want to say that I already tried the var=`function` &amp;amp; and it didn't work, here is a simple test:&lt;BR /&gt;"&lt;BR /&gt;function titi {&lt;BR /&gt;  rez=1&lt;BR /&gt;  while [ 1 ]; do&lt;BR /&gt;  for i in /* ; do echo $i&amp;gt;&amp;gt;/scripts/test/titi.log;&lt;BR /&gt;  done&lt;BR /&gt;    if [ `wc -l /scripts/test/titi.log | cut -d" " -f1` -gt 37000 ]; then&lt;BR /&gt;      rez=2; break;&lt;BR /&gt;    fi&lt;BR /&gt;    sleep 1&lt;BR /&gt;  done&lt;BR /&gt;  echo $rez&lt;BR /&gt;  return $rez&lt;BR /&gt;}&lt;BR /&gt;rez=900&lt;BR /&gt;rez=`titi` &amp;amp;&lt;BR /&gt;while [ 1 ]; do&lt;BR /&gt;if [ `jobs | wc -l` -eq 0 ]; then break;&lt;BR /&gt;else echo Working;&lt;BR /&gt;fi&lt;BR /&gt;sleep 2&lt;BR /&gt;done&lt;BR /&gt;echo $rez&lt;BR /&gt;"&lt;BR /&gt; at the end I see the value 900 displayed, not 2, what I expect; what can be the problem?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;</description>
      <pubDate>Thu, 01 Jul 2004 06:24:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320278#M187260</guid>
      <dc:creator>vtihu</dc:creator>
      <dc:date>2004-07-01T06:24:10Z</dc:date>
    </item>
    <item>
      <title>Re: communication with background function</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320279#M187261</link>
      <description>That "rez" bit should work if you don't enclose it in ` characters.  However, the "trap" then won't work.  So, I think, in order  to get everything to work, you'll probably need to take your whole "titi" function and make is a separate script instead.</description>
      <pubDate>Thu, 01 Jul 2004 07:06:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320279#M187261</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-07-01T07:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: communication with background function</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320280#M187262</link>
      <description>&lt;BR /&gt;  Even when changing the function into a script it doesn't work, as if the output would have been "stolen" and didn't reach the intended recipient; if there are no other suggestions I think I'll finally have to use the temp file approach which is very "robust" and works fine, with some extra coding!&lt;BR /&gt;</description>
      <pubDate>Thu, 01 Jul 2004 07:32:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320280#M187262</guid>
      <dc:creator>vtihu</dc:creator>
      <dc:date>2004-07-01T07:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: communication with background function</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320281#M187263</link>
      <description>hai,&lt;BR /&gt;&lt;BR /&gt; We can get the back ground running process with some debugging statements and results redirection to a common file.&lt;BR /&gt;&lt;BR /&gt; We can not use the environment variables in this situation,because client process can not change main process variables value.&lt;BR /&gt;&lt;BR /&gt; We cannot check the return type of backgroundly running process. It may be end at any time. &lt;BR /&gt;&lt;BR /&gt; The best way is to put the debug statements in the begin,during the operation and end of operation withit's PID and identifier like that.&lt;BR /&gt;&lt;BR /&gt; We can use pipe in the script to interact with the main process to know the completion of execution.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Muthukumar</description>
      <pubDate>Thu, 01 Jul 2004 08:25:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320281#M187263</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-07-01T08:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: communication with background function</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320282#M187264</link>
      <description>Sorry, I'm a bit stupid.  That bit can't work properly.  It will only work if the "&amp;amp;" is inside the ` marks.  However, then the shell will wait for the script to finish.&lt;BR /&gt; &lt;BR /&gt;Seems you can't persuade the parent to "capture" the information from the child if it's run in the background without using a file or named pipe.  .&lt;BR /&gt; &lt;BR /&gt;</description>
      <pubDate>Thu, 01 Jul 2004 09:01:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320282#M187264</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-07-01T09:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: communication with background function</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320283#M187265</link>
      <description>&lt;BR /&gt;  Yes, it seems ok with &amp;amp; inside because the assignment has to wait for the output to be produced etc., but then I don't have multithreading; I already changed the script to use temp files, but there is a price to pay which seems to be serious - the code gets a lot complicated...</description>
      <pubDate>Thu, 01 Jul 2004 09:51:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320283#M187265</guid>
      <dc:creator>vtihu</dc:creator>
      <dc:date>2004-07-01T09:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: communication with background function</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320284#M187266</link>
      <description>Can't you combine the two approaches.&lt;BR /&gt; &lt;BR /&gt;Have your function as a separate script.  Run it in the background. Use the "trap" thing to determine when the function script has finished.  The function called by "trap" can then use "wait" to determine the function scripts' exit status and then read a file, thoughtfully provided by the function script that contains the information you wanted.</description>
      <pubDate>Thu, 01 Jul 2004 09:57:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320284#M187266</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-07-01T09:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: communication with background function</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320285#M187267</link>
      <description>Hai,&lt;BR /&gt;&lt;BR /&gt; There is a discussion related to this one is at location.&lt;BR /&gt; &lt;A href="http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=611644" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=611644&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Muthukumar.</description>
      <pubDate>Thu, 01 Jul 2004 23:20:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320285#M187267</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-07-01T23:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: communication with background function</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320286#M187268</link>
      <description>&lt;BR /&gt;  Mark, I agree, this combination seems to be the most "elegant" way to check for a child background function / script completion and it's return value; one problem is when you have many parameters and / or side effects and respond to the parent script in a more complex way than a mere return value, so you have also to use temp files&lt;BR /&gt;  Muthukumar, I can't open that link; maybe you can check, I think it can be useful..&lt;BR /&gt;&lt;BR /&gt;Thank you all&lt;BR /&gt;&lt;BR /&gt;Vlad&lt;BR /&gt;</description>
      <pubDate>Fri, 02 Jul 2004 03:55:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320286#M187268</guid>
      <dc:creator>vtihu</dc:creator>
      <dc:date>2004-07-02T03:55:46Z</dc:date>
    </item>
    <item>
      <title>Re: communication with background function</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320287#M187269</link>
      <description>Hai,&lt;BR /&gt;&lt;BR /&gt; Let us go with a example shell script.&lt;BR /&gt; &lt;BR /&gt; #!/usr/bin/ksh&lt;BR /&gt; # test.ksh&lt;BR /&gt; # Debug mode&lt;BR /&gt; set -x&lt;BR /&gt; &lt;BR /&gt; # parent process ID&lt;BR /&gt; echo "PPID $$"&lt;BR /&gt; fun()&lt;BR /&gt; {&lt;BR /&gt;  id=$1&lt;BR /&gt;   echo test $id&lt;BR /&gt;   test=1;export test&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; call()&lt;BR /&gt; {&lt;BR /&gt;         fun 1 &amp;amp;&lt;BR /&gt;         echo "PID $!" # child 1 process ID&lt;BR /&gt;         fun 2 &amp;amp;&lt;BR /&gt;         echo "PID $!" # child 2 process ID&lt;BR /&gt;         # it is good to redirect child pid value to some variable and using ps command check the completion of process.&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; call&lt;BR /&gt; echo $test&lt;BR /&gt;&lt;BR /&gt; We cannot set use the environent variables between the child and parent process. So use two files as status.log and return.log.&lt;BR /&gt; &lt;BR /&gt; Use echo statements in the action of background process. Try to redirect all processing debug statements to that file. Use the separate ID for every child. Use the separate return statement and redirect that to the return.log file. Use the return.log file as /var/tmp/return _$ID.log . where ID is the identifier sent from parent to child. If it contains an entry,it is finised or analyse the return value's from that.&lt;BR /&gt; &lt;BR /&gt; We can connect the background and parent process with unified files. we can control the child process actions with log files and as well as PIPE's. If we want to communicate to parent then, use checking conditions related with the log files.&lt;BR /&gt; &lt;BR /&gt; The link &lt;A href="http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=611644" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=611644&lt;/A&gt; is related to know the back ground process execution status analysis.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Muthukumar.</description>
      <pubDate>Fri, 02 Jul 2004 06:21:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/communication-with-background-function/m-p/3320287#M187269</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-07-02T06:21:07Z</dc:date>
    </item>
  </channel>
</rss>

