r/linux_programming • u/stewartmatheson • Jul 03 '20
Non blocking process communication
I'm in the process of teaching myself Linux system programming using C. As a learning exercise I would like to create a program that runs in a terminal window. This program would wait for an event that would instruct it to create a new compile process and display the results of that process in the terminal. I would then run this program in the background while coding to get live results of what errors my program has as I make changes.
Currently I have the following program.
While it's rough it does give an idea of what I'm trying to do.
I have created a fifo with the mkfifo command and the source code posted above blocks and reads from the fifo. I have set my vim up to write to the same fifo when I write a file thus closing the loop. Everything works fine when my program is running. The issue I'm having is that vim becomes blocked if it tries to write to the fifo while my program is not running. I write to the fifo from vim with the following command.
echo "test" > .socket-file
I'd like for vim not to be blocked if my program is not running. For this exercise is using a fifo the correct approach? Could I send a signal somehow? I slightly confused about the best direction to take. Thanks in advance.
View all comments
Show parent comment
0
u/stewartmatheson Aug 19 '20
Right... so the title does not really make it clear. In the OP the goal was to make the code/command sending the event/notification non blocking. The program it's self can block however like you have said the approach is naive. Given that you seem knowldegeable on this subject could you share the reasons why you have said it's naive other than "it wont work". As I said github links are good but the best way for you to add value to this thread would be to break down your reaons in more detail so others can benefit form your knowlege. Thanks in advance for your reply.