0

The device-file 'debug_port' is an output of some port. I have three scripts:

The first script waits for some info from the port, and at the same time logs data in a log file, then performs its work, with some greps from log and echos to debug_port.

#first.sh
pkill cat
cat debug_port > $logfile1 &
running=$!
# perform its tasks...
kill $running
killall -s SIGPIPE cat
pkill -P $$
rm $logfile1

The second one waits for some other info and performs another work.

#second.sh
pkill cat
cat debug_port > $logfile2 &
running=$!
# <<< there is problem: no output from 'debug_port'
# perform its tasks...
kill $running
rm $logfile2

And caller calls both of them sequentially

#caller.sh
./first.sh
./second.sh

Problem is, I have no output from 'debug_port', in the second script. However I am sure there should be some.

4
  • I have fixed the grammar to make it readable. Can you check (read), to see if it says what you intended. Commented Nov 23, 2019 at 18:34
  • 2
    Your scripts are very aggressive, somebody (a process) is going to get hurt. Those pkills and killalls will affect the other script, and other scripts being run by this user (all users if run by root). Commented Nov 23, 2019 at 18:37
  • @ctrl-alt-delor, thank you Commented Nov 23, 2019 at 18:43
  • @ctrl-alt-delor, I know, that they are aggresive, my main guess is that somewhere I do not terminate one of background tasks, so I wanted to show, it looks like that my guess is wrong Commented Nov 23, 2019 at 18:50

1 Answer 1

2

As you are reading a device file. It is possible that it is not seekable: that it is a single stream. If so the a read from one process, will preclude a read of the same byte by another process. Therefore you should not read with two processes at the same time.

If you need to do this, then you need to fork the stream. This may result in more memory ram/disk (depending on implementation) being used, as data has to be stored somewhere. The about of memory use will depend on the lay between the processes.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .