6

I've created a named pipe on Debian using mkfifo pipe.in. I want to write to this pipe from Matlab.

To do this, I use the following matlab command:

unix( 'cat <myfile> > pipe.in' )

Where <myfile> is a text file and pipe.in is the pipe I created with mkfifo.

In many cases, the process associated to the pipe crashed for many reason (but any reason beyond the use of the unix and cat command). The crash can be normal in several cases.

Executing the above command causes Matlab to freeze, and I can't regain control with CTRL+C.

Is there another way to release Matlab without requiring me to kill the process?

Guuk
  • 199
  • 7
  • 2
    Try running the `cat` command in the background by appending `&` to the command... –  Jan 17 '13 at 15:28
  • How did you create the pipe? – Rody Oldenhuis Jan 17 '13 at 15:31
  • @EitanT I try it and it unblocks MatLab but in my case I must wait that the unix command terminates to be sure that the process is completed –  Jan 17 '13 at 16:08
  • @RodyOldenhuis I create the pipe as follows: `mkfifo pipe.i; mkfifo pipe.out; time echo ""| > log &` –  Jan 17 '13 at 16:09
  • @Guuk what's the size of the file you're trying to send through the pipe? –  Jan 17 '13 at 16:10
  • @EitanT it's a small file (around 200 lines) but each line of this file is a command for the external process () and the command `unix` waits that all commands has been read by the external process. –  Jan 17 '13 at 16:14
  • @Guuk Try to reduce the problem. Can you work on an even smaller file (say, 10 lines) and see if MATLAB crashes? How long does it take to execute each line? –  Jan 17 '13 at 16:19
  • @EitanT I will try with a smaller file but in my case when the process associated to the pipe () crashed, I delete pipe.in and pipe.out (this can append when the cat command is executed) so the problem is that I can't use CTRL+C command to unfreeze Matlab. I have try this in a terminal: `mkfifo pip;cat > pip;` in an other terminal I delete pip and in this case in the first terminal do CTRL+C and the cat command is terminated as I want. –  Jan 17 '13 at 16:38
  • 2
    What happens if you simply `cat` the file without the pipe, does this freeze? Have you tried opening the pipe from within matlab using `fopen` and writing to it using `fprintf`? – slayton Jan 17 '13 at 17:22

1 Answers1

2

Unblocking Matlab

You can unblock Matlab by sending the QUIT signal by pressing CTRL-\ in the terminal that you launched Matlab from.

Why Matlab is freezing

Matlab is freezing because the unix function never returns because cat <myfile> > pipe never terminates.

Executing cat <myfile> > pipe.in in a terminal demonstrates the same "freezing" behavior.

My bash-fu isn't very good, but I think that something must be reading from the pipe before the writer can terminate.

Create a temporary pipe and file

mkfifo /tmp/tempPipe
echo "1 2 3 4 5 6 7 8 0" > /tmp/tempFile

Write to the pipe

This command will not terminate:

cat /tmp/tempFile > /tmp/tempPipe 

This command will:

cat /tmp/tempFile > /tmp/tempPipe & cat < /tmp/tempPipe

I expect that if you create a reading process then your Matlab call to unix will terminate.

slayton
  • 121
  • 4
  • The freezing "behavior" is not for me a real problem. In the classic case, I would expect that the whole command go through the pipe (because I must wait to do other operations). The freezing behavior is not a problem in a terminal because I can stop it by pressing CTRL+C. But in matlab, I can't use this command. –  Jan 17 '13 at 20:00
  • For information, the main process that is managed by the command trough the pipe is a numerical solvor. So, in my case, I have to send commands to the solvor using the pipe (each group of commands leads to a numerical computation). I am waiting that the group of commands go to the pipe and when the last command go to the pipe, I can continue many operations in MatLab before sending new commands. –  Jan 17 '13 at 20:10
  • I want just to stop the freezing behavior when the solvor crashs (and the pipe are deleted). –  Jan 17 '13 at 20:11
  • @Guuk then use CTRL-\ – slayton Jan 18 '13 at 01:13
  • I will try it but in the future I want to use my matlab program on a cluster and I can't use this. Therefore I looked for an automatic so –  Jan 18 '13 at 06:28
  • Therefore I looked for an automatic way to deal with this freezing problem. –  Jan 18 '13 at 06:47