Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 333283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:56:48+00:00 2026-05-12T09:56:48+00:00

Normally I would start a command like longcommand &; I know you can redirect

  • 0

Normally I would start a command like

longcommand &;

I know you can redirect it by doing something like

longcommand > /dev/null;

for instance to get rid of the output or

longcommand 2>&1 > output.log

to capture output.

But I sometimes forget, and was wondering if there is a way to capture or redirect after the fact.

longcommand
ctrl-z
bg 2>&1 > /dev/null

or something like that so I can continue using the terminal without messages popping up on the terminal.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:56:49+00:00Added an answer on May 12, 2026 at 9:56 am

    See Redirecting Output from a Running Process.

    Firstly I run the command cat > foo1 in one session and test that data from stdin is copied to the file. Then in another session I redirect the output.

    Firstly find the PID of the process:

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

    Now check the file handles it has open:

    $ ls -l /proc/6760/fd
    total 3
    lrwx—— 1 rjc rjc 64 Feb 27 15:32 0 -> /dev/pts/5
    l-wx—— 1 rjc rjc 64 Feb 27 15:32 1 -> /tmp/foo1
    lrwx—— 1 rjc rjc 64 Feb 27 15:32 2 -> /dev/pts/5
    

    Now run GDB:

    $ gdb -p 6760 /bin/cat
    GNU gdb 6.4.90-debian
    
    [license stuff snipped]
    
    Attaching to program: /bin/cat, process 6760
    
    [snip other stuff that's not interesting now]
    
    (gdb) p close(1)
    $1 = 0
    (gdb) p creat("/tmp/foo3", 0600)
    $2 = 1
    (gdb) q
    The program is running. Quit anyway (and detach it)? (y or n) y
    Detaching from program: /bin/cat, process 6760
    

    The p command in GDB will print the value of an expression, an expression can be a function to call, it can be a system call… So I execute a close() system call and pass file handle 1, then I execute a creat() system call to open a new file. The result of the creat() was 1 which means that it replaced the previous file handle. If I wanted to use the same file for stdout and stderr or if I wanted to replace a file handle with some other number then I would need to call the dup2() system call to achieve that result.

    For this example I chose to use creat() instead of open() because there are fewer parameter. The C macros for the flags are not usable from GDB (it doesn’t use C headers) so I would have to read header files to discover this – it’s not that hard to do so but would take more time. Note that 0600 is the octal permission for the owner having read/write access and the group and others having no access. It would also work to use 0 for that parameter and run chmod on the file later on.

    After that I verify the result:

    ls -l /proc/6760/fd/
    total 3
    lrwx—— 1 rjc rjc 64 2008-02-27 15:32 0 -> /dev/pts/5
    l-wx—— 1 rjc rjc 64 2008-02-27 15:32 1 -> /tmp/foo3 <====
    lrwx—— 1 rjc rjc 64 2008-02-27 15:32 2 -> /dev/pts/5
    

    Typing more data in to cat results in the file /tmp/foo3 being appended to.

    If you want to close the original session you need to close all file handles for it, open a new device that can be the controlling tty, and then call setsid().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 199k
  • Answers 199k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Those pointers look particularly gross. The problem with doing it… May 12, 2026 at 7:42 pm
  • Editorial Team
    Editorial Team added an answer If your programming language doesn't have support for fancy time… May 12, 2026 at 7:42 pm
  • Editorial Team
    Editorial Team added an answer strcat concatenates two char pointers like so. char *p1[12]; char… May 12, 2026 at 7:42 pm

Related Questions

I start Firefox (Linux) via command line using a cron-job. When there is no
I have a VB6 console app and it uses command line parameters. For debugging,
I've recently been building a test framework for a bit of C# I've been
Working on a little Ruby script that goes out to the web and crawls

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.