Home » Questions » Computers [ Ask a new question ]

In tcsh, how can I silence the output of an already running background process?

In tcsh, how can I silence the output of an already running background process?

If I've launched a job into the background how can I redirect its output to /dev/null or in some way silence its output?

Asked by: Guest | Views: 290
Total answers/comments: 1
Guest [Entry]

"Taken from the link ""redirecting output from a running process"" given in this StackOverflow answer to a similar question. You might compare these directions with this answer that discusses the same trick for other purposes.

Here's the basic process, assuming the command is already running. This works well for regular STDOUT output. The original writeup uses cat > foo1 as an example long-running output program.

Depending on the particulars of the process you want to silence, you may need to perform this process on STDERR (or other ouput streams) instead of, or in addition to, STDOUT.

Find the process PID.

$ ps aux | grep cat
user 6760 0.0 0.0 1580 376 pts/5 S+ 15:31 0:00 cat

Connect to the process with GDB.

$ gdb -p 6760 /bin/cat
GNU gdb 6.4.90-debian
Copyright © 2006 Free Software Foundation, Inc
[lots more license stuff snipped]
Attaching to program: /bin/cat, process 6760
[snip other stuff that's not interesting now]

In GDB, close the process STDOUT. (""(gdb)"" is the GDB prompt; type in what you see on those lines. The other lines are example output.)

(gdb) p close(1)
$1 = 0

In GDB, open a new file. Notes: the return value ""1"" indicates the new file was opened as STDOUT; ""0600"" is the mode (file permissions) of the new file (meaning ""readable-and-writable to owner, not to anyone else"").

(gdb) p creat(“/tmp/foo3″, 0600)
$2 = 1

Quit GDB; leave the process running.

(gdb) q
The program is running. Quit anyway (and detach it)? (y or n) y
Detaching from program: /bin/cat, process 6760

Source"