I made a C program, it forks 2 processes and each one of them uses
to call 2 scripts (script1.sh and script2.sh), what I want to do is let them write in a file (output.txt) in parallel but in different moments. For now my script1.sh (from process P1) write in the file for first, and then script2.sh (from process P2) write in the same file, but I need them to write in this way:
time 1: P1 writes 2 words in "output.txt" time 2: P2 wirtes 3 words in "output.txt" time 3: P1 writes 1 word in "output.txt" time 4: P2 writes 6 words in "output.txt" etc...
I know that
function is synchronous, but I succeeded in making it asynchronous using
The problem is that I don't know how to do that, because if P1 calls script1.sh with "&" it executes during P2 without pauses, so that's not what I want. I also know how to stop P1 using
pkill -f "script1.sh
so maybe it helps I don't know.
How can I reach that aim? Thanks