1

I am using fuser the output is like this:

$ fuser / 
/:                    1354rc  1362r  1370rc  1371rc  1395rc  1399rc  1403rc  1410rc  1414rc  1428r  1451rc  1458rc  1470rc  1472rc  1477rc  1480rc  1487rc  1492rc  1500rc  1504rc  1508r  1513r  1516rc  1551r  1563rc  1567rc  1569rc  1586rc  1592rc  1629r  1630r  1633r  1645r  1660r  1695rc  1712rc  1728rc  1885r  2262rc  2273r  2585r  2602r  3342r  3799r

I understand this but when i pipe it to wc or nl something goes wrong that output looks like this. can anyone tel me why?

$ fuser / | nl
/:                  rcrrcrcrcrcrcrcrcrrcrcrcrcrcrcrcrcrcrcrrrcrrcrcrcrcrcrrrrrrcrcrcrrcrrrrrr
     1    1354  1362  1370  1371  1395  1399  1403  1410  1414  1428  1451  1458  1470  1472  1477  1480  1487  1492  1500  1504  1508  1513  1516  1551  1563  1567  1569  1586  1592  1629  1630  1633  1645  1660  1695  1712  1728  1885  2262  2273  2585  2602  3342  3799  4618

2 Answers 2

2

part of fuser is sent to stdout (standard output), and part to standard error.

how is output split ?

piping mechanism only catch stdout.

plain fuser

mybox $ fuser /
/:                     350r   356r   357r   364r 10484rc 10485r

now redirecting, see pid are in a, while type of file (c or r) is in stderr.

mybox $ fuser / > a
/:                  rrrrrcr

file "a" do not end with a new line.

mybox $ cat a
   350   356   357   364 10484 10485mybox $

now redirecting both.

mybox $ fuser / > aa 2> bb

mybox $ cat aa
   350   356   357   364 10484 10485mybox $
mybox $ cat bb
/:                  rrrrrcr
  • 2> redirect stderr

to pipe both in one command

mybox $ fuser / > cc 2>&1
mybox $ fuser / 2>&1 | wc
    1       8      71
mybox $ fuser / 2>&1 | nl
    1  /:                     350r   356r   357r   364r 10484rc 10485r 11761r
  • 2>&1 "merge" stdout and stderr

why is output split ?

one of the main use of fuser is to kill process "holding" mount point.

from my command above, you could use content of a file to kill all process.

mybox $ fuser /foo/bar > a
/foo/bar:                  rrrrrcr

mybox $ cat a
   350   356   357   364 10484 10485mybox $
mybox $ kill $(<a)
  • $( ) syntax mean: content of file 'a'
1
  • That was amazing but why should the output be like that. it's wired that for example a part of "1234rc" be output and a part of it be error. and if so why all of it (output and error) will be print in diplay Commented Sep 15, 2014 at 11:45
1

fuser was written to send part of the output to stdout and part of the output to stderr. This was done for two reasons:

  1. It means you can pipe all the matching pids to another process
  2. The POSIX standard said so

It's not the easiest way to write and debug something but it has been a long-lived standard so love or hate it, that's the way it sends its output. It means if you pipe or redirect it you get lots of pids or lots of flags but not both.

For more details on why it is like that, see #166417

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.