How to fork gnuplot, write an initial string to it then background the process. Mean while parent is fetching data and writing to data file.This will run but after one replot gnuplot does not update as if dead.Can run similar program putting gnuplot string(DATA section) in file of its own and spawn gnuplot with this file as its source.Why does this code seem to freeze.How to fork open pipe write to it,exit but leave process running.

#!/usr/bin/perl -w my $pid; $pid = fork; if($pid == 0) { my $pid1 = open(CHILD, "|-", "gnuplot -persist ") or die "Couldn't + fork: $!\n"; local $/=undef; my $plot=<DATA>; print CHILD "$plot\n"; close(CHILD); print"forking\n"; exit; } use LWP::Simple; use Fcntl qw(:DEFAULT :flock); $|++; $SIG{TERM}=sub{print "ok1\n";alarm(0);exit;}; my $url='https://www.cryptonator.com/api/ticker/btc-gbp'; print"ok2\n"; my $interval = 30; # seconds between calls fetch(); sub fetch{ print"ok3\n"; my $replie = get($url); print"$replie \n"; my($a,$b,$c,$d)= $replie =~ /^.+?(\d+\.\d+).+?(\d+\.\d+)?.+?(\d+\ +.\d+).+?(\d+).*$/; $a="not defined" unless defined($a); $b="not defined" unless defined($b); $c="not defined" unless defined($c); $d="not defined" unless defined($d); open(OUT,">>","/home/philip/Desktop/PERLBITCOIN/TICKER/bitgbp1 +.dat") or die "BIT File open error $!\n"; unless (flock(OUT, LOCK_EX|LOCK_NB)) { warn "can't immediately write-lock the file ($!), blocking + ..."; unless (flock(OUT, LOCK_EX)) { die "can't get write-lock on numfile: $!"; } } print OUT "$c,$a,$d\n"; flock(OUT, LOCK_UN) or die "cant unlock file\n"; close(OUT); #print "$c,$a,$d\n"; alarm($interval); }; $SIG{ALRM}=\&fetch; 1 while 1; __DATA__ reset delta_v(x) = ( vD = x - old_v, old_v = x, vD) old_v = NaN unset key set xtics border in scale 0,0 nomirror rotate by -90 offset character + 0,0 autojustify set datafile separator ',' set bmargin at screen 0.15 #set palette defined (100 "red", 200 "green", 300 "blue") set palette defined (-1 "red", 1 "#1B6821") #set palette model RGB defined ( -1 'red', 1 '#006400', 0 'black' ) set cbrange [-1:1] set grid set yrange [*:*] unset colorbox set style fill solid noborder #set xrange [1446061653-946684800:1446064653-946684800] set xdata time set timefmt "%s" set format x "%H:%M" # or anything else set xlabel "time" set xtics autofreq data=system("tail -n 1 '/home/philip/Desktop/PERLBITCOIN/TICKER/bitgbp +1.dat' | awk '{print $0}'") print delta_v(2) plot '< tail -n 40 /home/philip/Desktop/PERLBITCOIN/TICKER/bitgbp1.dat +' using 3:2:((delta_v($2) > 0.0) ? 1 : -1 )with impulses lw 2 palett +e pause 10 reread replot;

In reply to fork spawn write background problem by grasshopper!!!

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.