2

I ran make in the terminal for Kismet on my Pi and it's been outputting to the terminal every 10 to 15 seconds, regardless of it is being run in the background or not.

I tried using CTRL+Z and running bg command. Although the jobs command lists it as Running and lists the command as make & to indicate that it's in the background, the output is still coming to the terminal.

I also paused it again and then ran bg; %+ >1 /dev/null to try to send the STDOUT to /dev/null, but it is still outputting to the screen.

Is there a way to make a job run in the background and only get STDERR messages to the terminal?

Here is the output:

First Attempt:

[1]+  Stopped                 make
root@stormpi:/usr/local/kismet# jobs
[1]+  Stopped                 make
root@stormpi:/usr/local/kismet# bg
[1]+ make &
root@stormpi:/usr/local/kismet# jobs
[1]+  Running                 make &
root@stormpi:/usr/local/kismet# In file included from entrytracker.h:36,
                 from system_monitor.cc:33:
trackedelement.h: In member function ‘void tracker_element_core_vector<T, TT>::set(tracker_element_core_vector<T, TT>::const_iterator, tracker_element_core_vector<T, TT>::const_iterator) [with T = double; tracker_type TT = (tracker_type)22]’:
trackedelement.h:1553:18: note: parameter passing for argument of type ‘tracker_element_core_vector<double, (tracker_type)22>::const_iterator’ {aka ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double> >’} changed in GCC 7.1
     virtual void set(const_iterator a, const_iterator b) {
                  ^~~
trackedelement.h:1553:18: note: parameter passing for argument of type ‘tracker_element_core_vector<double, (tracker_type)22>::const_iterator’ {aka ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double> >’} changed in GCC 7.1

2nd Attempt:

jobs
[1]+  Running                 make &
root@stormpi:/usr/local/kismet# fg
make
^Z
[1]+  Stopped                 make
root@stormpi:/usr/local/kismet# jobs
[1]+  Stopped                 make
root@stormpi:/usr/local/kismet# bg; %+ >1 /dev/null
[1]+ make &
make
g++ -std=gnu++17 -MM -MP -Wall -Wno-unknown-warning-option -Wno-deprecated-declarations -Wno-format-truncation -Wno-unused-local-typedefs -Wno-unused-function -Wno-infinite-recursion -g -I. -fPIE -g -O2 -O3 -pthread -DKS_STR_ENCODING_NONE    -MT gpsgpsd_v3.cc.o gpsgpsd_v3.cc -MF gpsgpsd_v3.cc.d
g++ -std=gnu++17 -Wall -Wno-unknown-warning-option -Wno-deprecated-declarations -Wno-format-truncation -Wno-unused-local-typedefs -Wno-unused-function -Wno-infinite-recursion -g -I. -fPIE -g -O2 -O3 -pthread -DKS_STR_ENCODING_NONE    -c gpsgpsd_v3.cc -o gpsgpsd_v3.cc.o

1 Answers1

2

These messages you get are most likely printed to standard error and not standard output ... You can verify which is which by running make through strace like so:

strace -e write make ...

Then see the file descriptor(the first argument in the write() call) ... 2 is standard error and 1 is standard output.

To hide these messages, you might want to direct both standard output(file descriptor 1) and standard error(file descriptor 2) to /dev/null(or to another file) before the command gets executed but, like so:

make ... > /dev/null 2>&1 &

And not like so:

make ... 2>&1 > /dev/null &

See redirection in bash ... Specifically this excerpt:

Note that the order of redirections is significant. For example, the command

ls > dirlist 2>&1 directs both standard output (file descriptor 1) and standard error (file descriptor 2) to the file dirlist, while the command

ls 2>&1 > dirlist directs only the standard output to file dirlist, because the standard error was made a copy of the standard output before the standard output was redirected to dirlist.

An alternate way for directing both STDOUT and STDERR in bash is using &> e.g. like so:

make ... &> /dev/null &

To direct STDOUT only, use just > e.g. like so:

make ... > /dev/null &

You might want to direct to a log file for later inspection instead of /dev/null and in this case you might want to use the append operator >> e.g. directing STDOUT like so:

make ... >> file.log &

Or direct both STDOUT and STDERR e.g. like so:

make ... &>> file.log &

Side notes:

  1. >1 when it gets executed as intended e.g. command >1 (>1 in your bg; %+ >1 /dev/null example will not) will direct standard output to an actual file named 1 in the current working directory.

  2. To direct to a file descriptor >&FDNUMBER is used ... Where FDNUMBER is the number of the file descriptor e.g. >&2(direct STDOUT to STDERR) or 2>&1(direct STDERR to STDOUT).

  3. To manipulate and direct file descriptors of an already running process see different ways, specifically using GDB, in my answer to Forground a running process that was started with a script (MineCraft Server).

Raffa
  • 32,237