linux启动后返回命令行,linux – 在进程启动后,使用命令行重定向进程的STDERR/STDOUT?...

缺少关闭和重新打开您的tty(即注销和回来,这也可能会终止您的一些后台进程),你只有一个选择:

>使用gdb附加到相关进程,然后运行:

> p dup2(open(“/ dev / null”,0),1)

> p dup2(open(“/ dev / null”,0),2)

>分离

>退出

例如。:

$ tail -f /var/log/lastlog &

[1] 5636

$ ls -l /proc/5636/fd

total 0

lrwx------ 1 myuser myuser 64 Feb 27 07:36 0 -> /dev/pts/0

lrwx------ 1 myuser myuser 64 Feb 27 07:36 1 -> /dev/pts/0

lrwx------ 1 myuser myuser 64 Feb 27 07:36 2 -> /dev/pts/0

lr-x------ 1 myuser myuser 64 Feb 27 07:36 3 -> /var/log/lastlog

$ gdb -p 5636

GNU gdb 6.8-debian

Copyright (C) 2008 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law. Type "show copying"

and "show warranty" for details.

This GDB was configured as "x86_64-linux-gnu".

Attaching to process 5636

Reading symbols from /usr/bin/tail...(no debugging symbols found)...done.

Reading symbols from /lib/librt.so.1...(no debugging symbols found)...done.

Loaded symbols for /lib/librt.so.1

Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.

Loaded symbols for /lib/libc.so.6

Reading symbols from /lib/libpthread.so.0...(no debugging symbols found)...done.

[Thread debugging using libthread_db enabled]

[New Thread 0x7f3c8f5a66e0 (LWP 5636)]

Loaded symbols for /lib/libpthread.so.0

Reading symbols from /lib/ld-linux-x86-64.so.2...(no debugging symbols found)...done.

Loaded symbols for /lib64/ld-linux-x86-64.so.2

(no debugging symbols found)

0x00007f3c8eec7b50 in nanosleep () from /lib/libc.so.6

(gdb) p dup2(open("/dev/null",0),1)

[Switching to Thread 0x7f3c8f5a66e0 (LWP 5636)]

$1 = 1

(gdb) p dup2(open("/dev/null",0),2)

$2 = 2

(gdb) detach

Detaching from program: /usr/bin/tail, process 5636

(gdb) quit

$ ls -l /proc/5636/fd

total 0

lrwx------ 1 myuser myuser 64 Feb 27 07:36 0 -> /dev/pts/0

lrwx------ 1 myuser myuser 64 Feb 27 07:36 1 -> /dev/null

lrwx------ 1 myuser myuser 64 Feb 27 07:36 2 -> /dev/null

lr-x------ 1 myuser myuser 64 Feb 27 07:36 3 -> /var/log/lastlog

lr-x------ 1 myuser myuser 64 Feb 27 07:36 4 -> /dev/null

lr-x------ 1 myuser myuser 64 Feb 27 07:36 5 -> /dev/null

您还可以考虑:

>使用屏幕;屏幕提供几个虚拟TTY,您可以在不必打开新的SSH / telnet /等会话之间切换>使用nohup;这允许您关闭并重新打开会话,而不会在…过程中丢失任何后台进程。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值