LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-10-2006, 06:05 AM   #1
nutthick
Member
 
Registered: Jun 2004
Distribution: Slack
Posts: 214

Rep: Reputation: 30
Simple pipe in deadlock?


I'm setting up a pipe as follows:
Code:
mkfifo /tmp/mplayer_cmd
then starting the application with this code
Code:
cat /tmp/mplayer_cmd | mplayer -slave test.mp3
The file starts playing.
I then SSH in and type the following
Code:
echo pause > /tmp/mplayer_cmd
and the track pauses. However, any other commands I issue through echo just hang the prompt. From what I've read this is because the pipe is blocked, as there is nothing to read it. But the track paused, so it is being read. I'm lost. mkfifo(3) apparently solves it, but what does the (3) mean?

Can anyone help?

Thanks
 
Old 05-10-2006, 07:11 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by nutthick
I'm setting up a pipe as follows:
Code:
mkfifo /tmp/mplayer_cmd
then starting the application with this code
Code:
cat /tmp/mplayer_cmd | mplayer -slave test.mp3
The file starts playing.
I then SSH in and type the following
Code:
echo pause > /tmp/mplayer_cmd
and the track pauses. However, any other commands I issue through echo just hang the prompt.
What happens is that the pipe (fifo) is closed after the first echo. Try:
Code:
cat > /tmp/mplayer_cmd
and start typing multiple commands. Type <enter> after each command, and CTRL-d to close the pipe when you're done.

Quote:
Originally Posted by nutthick
I'm lost. mkfifo(3) apparently solves it, but what does the (3) mean?
"mkfifo(3)" means the man page of the "mkfifo" libc function which is in section 3 of the man-system, rather than the mkfifo command which is in section 1 of the manual.

"(3)" is mentioned because there are two different "mkfifo" man-pages. The command "man -k mkfifo" will show all man pages that deal with some "mkfifo" and the section they are in. The command "man 1 mkfifo" will show you the mkfifo man page of section 1 (executables and shell commands) while "man 3 mkfifo" will show the mkfifo C function which is in section 3 (C-library functions). Just "man mkfifo" will show the man page in the lowest numbered section that is called "mkfifo", so in this case it's equivalent to "man 1 mkfifo".

Even if there's no ambiguity to expect (you never know for sure which man pages people have installed), it considered good practice to mention the section when referring to man pages. It also is a brief way to indicate that a man page is refferred to.

To read about the man page sections, see the man page about "man", or better, see man(1).

Last edited by Hko; 05-10-2006 at 07:13 AM.
 
Old 05-10-2006, 07:31 AM   #3
ioerror
Member
 
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536

Rep: Reputation: 34
Quote:
cat /tmp/mplayer_cmd | mplayer -slave test.mp3
It's blocking because cat will exit after you type the first command (it stops when there is no more data).

You should specify the fifo directly to mplayer, e.g.:

Code:
mplayer -input file=/tmp/mplayer_cmd ...
I thinks that right, can't remember offhand (on my laptop at the moment, so can't check it).

Quote:
I'm lost. mkfifo(3) apparently solves it, but what does the (3) mean?
The 3 refers the section three of the man page system. See man 7 man for a description of the sections.

edit:
arrgh! Hko beat me to it again, I must stop going to make a cup of coffee in the middle of typing a post.

Last edited by ioerror; 05-10-2006 at 07:35 AM.
 
Old 05-10-2006, 07:59 AM   #4
nutthick
Member
 
Registered: Jun 2004
Distribution: Slack
Posts: 214

Original Poster
Rep: Reputation: 30
@Hko: Thanks for the reply and for explaining the (3) notation. You never know till you ask I'm still having a few issues with pipe. I set everything up as I explained before and use the cat > method to control it. But if the track finishes before I type in a command I get
Code:
Broken pipe
and have to delete and recreate the pipe file to get things going again. I managed to get it going though, look below


@ioerror: Thanks for the reply. That worked with echo. However, I have the problem as for Hko, if the track ends, the pipe stops working. The mplayer man says to use -idle to stop mplayer quitting and to keep the pipe, but the command isn't recognised. Any ideas?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apt Dependency Deadlock Quantumstate Debian 7 04-23-2006 09:33 AM
simple yet tricky pipe question rastadevil Programming 2 03-23-2006 09:02 PM
Diagnosing Deadlock jcase008 Linux - Software 3 07-03-2004 09:09 PM
How do I escape mysql RPM erase deadlock ?? tuka Linux - Newbie 1 09-06-2003 10:54 PM
deadlock rajani Programming 0 03-11-2002 06:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration