Por que o fusor usa o STDERR?

1
SERVER:~ # fuser -uc /var/log
/var/log:             6824(daemon)  9902(root) 14011(root) 14084(root) 14208(lp)
SERVER:~ # fuser -uc /var/log 2>/dev/null
  6824  9902 14011 14084 14208SERVER:~ # 
SERVER:~ # 

A pergunta: é por razões históricas ou há alguma razão técnica para isso?

    
por thequestionthequestion 06.11.2014 / 16:54

2 respostas

4

O utilitário fuser está limitado pelos padrões abaixo:

O racional para isto ter saída de informações de diagnóstico para stderr . Isso não inclui apenas os erros, mas qualquer coisa que não seja a saída de dados primária do utilitário.
Embora esses dados sejam úteis, se forem incluídos no stdout , a análise do resultado será cada vez mais difícil.

Se stdout estiver sendo redirecionado ou filtrado, o stderr continuará imprimindo no terminal.

De acordo com o IEEE Std 1003.1, 2004 Edition , o utilitário fuser :

The *fuser* utility shall write to standard error additional information about the  
named  files indicating how the file is being used.   

STDERR

The fuser utility shall write diagnostic messages to standard error. The fuser utility also shall write the following to standard error:

  • The pathname of each named file is written followed immediately by a colon.

  • For each process ID written to standard output, the character 'c' shall be written to standard error if the process is using the file as its current directory and the character 'r' shall be written to standard error if the process is using the file as its root directory. Implementations may write other alphabetic characters to indicate other uses of files.

  • When the -u option is specified, characters indicating the use of the file shall be followed immediately by the user name, in parentheses, corresponding to the process' real user ID. If the user name cannot be resolved from the process' real user ID, the process' real user ID shall be written instead of the user name.

When standard output and standard error are directed to the same file, the output shall be interleaved so that the filename appears at the start of each line, followed by the process ID and characters indicating the use of the file. Then, if the -u option is specified, the user name or user ID for each process using that file shall be written.

A <newline> shall be written to standard error after the last output described above for each file operand.

Referência

IEEE Std 1003.1, edição 2004

    
por 06.11.2014 / 17:43
2

É intencional.

fuser gera um formato "bruto" para stdout que inclui apenas IDs de processo e separadores de espaço entre eles. Este formato destina-se a ser conveniente para canalizar para outro processo ou manipular com sed , etc ... Além disso, ele gera informações extras destinadas a humanos para stderr, intercaladas e sincronizadas com a saída stdout. Isso inclui o tipo de uso que o processo está fazendo do arquivo e outras informações. A idéia é que essa informação "extra" não precise ir para o que quer que seja que você canalize a saída de fuser para, e enviá-la para stderr, é o que acontece por padrão.

    
por 06.11.2014 / 17:19

Tags