V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
liyongjun0803
V2EX  ›  Linux

我的输出去哪了?

  •  
  •   liyongjun0803 · 2020-04-23 17:20:39 +08:00 · 2533 次点击
    这是一个创建于 1462 天前的主题,其中的信息可能已经有所发展或是发生改变。

    C 语言写了一个循环打印 hello world 的程序:

    #include <stdio.h>
    #include <unistd.h>
    
    int main(int argc, char argv[])
    {
            while (1)
            {
                    printf("#################################hello world\n");
                    sleep(1);
            }
            return 0;
    }
    

    编译、放入 /usr/bin 目录、增加开机自启:

    $ gcc hello.c -o hello.out
    
    $ sudo cp hello.out /usr/bin/
    
    $ cat /etc/rc5.d/S01hello 
    #! /bin/sh
    /usr/bin/hello.out &
    
    

    在开机自启里面我并没有将输出重定向到任何文件(不想加,做个实验),请问系统重启后,我这个后台运行的 /usr/bin/hello.out (PID = 535) 的输出去哪了?我还能找到它吗?

    $ ps -ef | grep hello
    root       535     1  0 15:21 ?        00:00:00 /usr/bin/hello.out
    

    以下是我进行的尝试,既不懂,也没有效果。

    strace -p 535 -ewrite
    
    sudo reptyr 535 -T
    

    下面是 /proc 中 535 进程的文件描述符信息,我能从这里得到输出数据吗?这里的 'socket:[15354]' 我能使用吗?怎样使用?

    # cd /proc/535/fd
    root@liyongjun-VirtualBox:/proc/535/fd# ll
    总用量 0
    dr-x------ 2 root root  0 4 月  23 15:23 ./
    dr-xr-xr-x 9 root root  0 4 月  23 15:22 ../
    lr-x------ 1 root root 64 4 月  23 15:23 0 -> /dev/null
    lrwx------ 1 root root 64 4 月  23 15:23 1 -> 'socket:[15354]'
    lrwx------ 1 root root 64 4 月  23 15:23 2 -> 'socket:[15354]'
    

    以上
    有没有大神指点一下?

    3 条回复    2020-04-23 18:37:17 +08:00
    robot1
        1
    robot1  
       2020-04-23 17:51:29 +08:00
    不太懂 大概看了下,stdin,stdout,stderr 分别是 0,1,2 你程序的 1,2 都指向了 socket?你有重定向输出吗
    zdy349
        2
    zdy349  
       2020-04-23 18:32:28 +08:00
    /var/log/boot.log 里找找
    wsy2220
        3
    wsy2220  
       2020-04-23 18:37:17 +08:00
    重定向到 systemd-journald 了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5442 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 07:06 · PVG 15:06 · LAX 00:06 · JFK 03:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.