On the server which is always connected I’m using this in a crontab:

@reboot nc -k -l 1337 < /tmp/fifo.fifo

On the client which is not always on the network or switched on I’m using this command:

nc -d $IP_OF_SERVER 1337 > /tmp/fifo.fifo & $SOME_COMMAND

The server listens always for a connection on the specified port (thanks to the -k parameter), the client just connects to the server when it needs to.

I’m using this for MPD and its FIFO visualizer. MPD runs on a remote host, but my MPD client (ncmpcpp) runs locally.

This is the important part of the ncmpcpp config on the local host:

mpd_host = "$IP_OF_SERVER"
visualizer_fifo_path = "/tmp/fifo.fifo"

This is the important part of the mpd config on the remote server:

audio_output {
        path    "/tmp/fifo.fifo"

Running the 'nc' command on my local machine seems to use a very high amount of resources … ~100% of my CPU performance.



Any ideas where the problem is? Or if this is normal and how I would improve this whole scenario?

Unfortunately it’s not possible to just specify a network-path for visualizer_fifo_path, like:

visualizer_fifo_path = "$IP_OF_SERVER:/tmp/fifo.fifo"

And it’s also not possible to mount the remote host via NFS and then use the FIFO which is mounted via NFS.

Here’s some output from dtruss:

$ >> ps aux | grep 1337
user            96823  95,2  0,0  2433292    576 s003  R+   12:16PM  37:27.77 nc -d 1337
user            96821   0,0  0,0  2447044   1084 s003  Ss+  12:16PM   0:00.00 bash -c nc -d 1337 > /tmp/volumio.fifo & ncmpcpp -c /Users/user/.ncmpcpp/config-volumio -s visualizer

$ >> sudo dtruss -p 96821
SYSCALL(args)            = return

$ >> sudo dtruss -p 96823
dtrace: 353433 dynamic variable drops with non-empty dirty list
SYSCALL(args)            = return
select(0x4, 0x7FFF5D031F90, 0x0, 0x0, 0x0)               = 1 0
select(0x4, 0x7FFF5D031F90, 0x0, 0x0, 0x0)               = 1 0
select(0x4, 0x7FFF5D031F90, 0x0, 0x0, 0x0)               = 2 0
read(0x3, "\260\377N\377\022\377\325\376X\376J\376\233\375\253\375\311\374\332\374\262\374\276\374\234\374\232\374_\374L\374\217\374v\374\321\374\255\374\006\375\341\374\a\375\372\374\314\374\323\374\305\374\306\374k\374z\374\267\373\355\373u\373\251\373s\373\230\373\200\373\271\373\363\373\026\374^\374h\3746\374P\374\333\373\375\373q\373\225\373\270\372\354\372\270\371\364\371'\371g\371\036\371\\\371b\371\217\371\331\371\371\371\0", 0x400)           = 1024 0
write(0x1, "\260\377N\377\022\377\325\376X\376J\376\233\375\253\375\311\374\332\374\262\374\276\374\234\374\232\374_\374L\374\217\374v\374\321\374\255\374\006\375\341\374\a\375\372\374\314\374\323\374\305\374\30
select(0x4, 0x7FFF5D031F90, 0x0, 0x0, 0x0)               = 1 0
select(0x4, 0x7FFF5D031F90, 0x0, 0x0, 0x0)               = 1 0
select(0x4, 0x7FFF5D031F90, 0x0, 0x0, 0x0)               = 1 0

PS: Maybe the problem is that 'nc' is started in 'tmux' together with 'ncmpcpp' …

tmux split-window -t "$session":1 -v -p 28 "nc -d $IP_OF_SERVER 1337 > /tmp/volumio.fifo & ncmpcpp -c $HOME/.ncmpcpp/config-volumio -s visualizer"

How would I permanently run 'nc -d $IP_OF_SERVER 1337' in the background, maybe also started by a crontab? Is there something like the '-k' parameter for connecting to a server?

migrated from serverfault.com Mar 8 '15 at 11:01

This question came from our site for system and network administrators.

  • Probably a bug in nc, what do you see if you trace the system calls, which nc is making? (Might be it is in an infinite loop of system calls each returning EAGAIN) – kasperd Mar 8 '15 at 11:27
  • I tried to provide the information you wanted with 'dtruss'. Please let me know if you need further information. And please tell me, how I can get that information (never did things like those before). – fooness Mar 8 '15 at 12:07
  • I'll leave this question for somebody who understands the dtruss output format better than me. The back-to-back select calls do look suspicious, but I can't figure out what the exact arguments and return values are in this case. – kasperd Mar 8 '15 at 13:27
  • Is there some other tool on OSX which gives you useful information? – fooness Mar 8 '15 at 13:43
  • sys_select(maxfd=4, readfd=<stuff>, write=except=NULL, timeout=NULL) (read-poll-loop), returns 1 or 2 for number of sockets ready. It's odd that when the socket is ready, it doesn't perform a read operation right away. – Andrew Domaszek Mar 8 '15 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.