【问题标题】:How to show background jobs in shell hidden by &如何在 & 隐藏的 shell 中显示后台作业
【发布时间】:2017-06-26 17:18:11
【问题描述】:

我通过一个Makefile 通过命令make install 运行一个网络服务器

Makefile的内容是

project : webserver.c

webserver.c : server/webserver.c
    gcc -g  -D_FORTIFY_SOURCE=0 -frecord-gcc-switches -fno-stack-protector -g  -o server/webserver -lpthread  -lnsl -lresolv -D_TS_ERRNO server/webserver.c
install :
    sudo /etc/init.d/fhttpd.init stop
    sudo cp server/webserver /usr/local/fhttpd/fhttpd
    sudo chmod 4755 /usr/local/fhttpd/fhttpd
    sudo /etc/init.d/fhttpd.init start

clean : 
    rm server/webserver 

fhttpd.init的内容是

httpd="/usr/local/fhttpd/fhttpd"
prog=fhttpd
port=8080
RETVAL=0

# disable ASLR so that lab exercise will work reliably
echo 0 > /proc/sys/kernel/randomize_va_space

start() {
                echo "Stopping $prog..."
                killall $prog
        echo -n $"Starting $prog: "
        $httpd $port &
}
stop() {
        echo -n $"Stopping $prog: "
        killall $prog
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        start
        ;;
  reload)
          start
        ;;
  *)
        echo $"Usage: $prog {start|stop|restart}"
        exit 1
esac

exit $RETVAL

我猜初始化使用& 使服务器在后台运行。但是在我使用该命令之后。我使用jobs 命令显示我所有的工作,我什么都看不到。但是如果我直接运行它,像这样

lhu343ai@server:~$ /usr/local/fhttpd/fhttpd 8080 &
[1] 7154
lhu343ai@server:~$ jobs
[1]+  Running                 /usr/local/fhttpd/fhttpd 8080 &

对我来说一切都很好。

如果我只使用make installsudo /etc/init.d/fhttpd.init startjobs 什么都不会显示。事实上,服务器运行正常。我只是不知道它是如何工作的,因为我在 /etc/init.d/fhttpd.init 中使用了&

我不知道为什么我不能在makefile 中使用“工作”。在这种情况下,我怎样才能找回后台程序。

【问题讨论】:

  • init 脚本在不同的 shell 中运行,因此它的作业在您的 shell 中不可见。您需要使用不同的工具(例如 pgrep)来验证服务器是否正在运行。
  • 你知道我想看看它的状态,怎么切换吗?
  • 您无法访问启动服务器的 shell。它不再运行了。我希望fhttpd status 会做点什么
  • 谢谢,这是一个让我们以某种方式使服务器崩溃的项目。如何查看它是否崩溃?
  • 尝试读取服务器日志

标签: shell makefile init ampersand


【解决方案1】:

我希望这个命令将执行提升到超级用户的用户空间:

sudo /etc/init.d/fhttpd.init start

因此,您不会在普通用户lhu343ai 中看到该过程。相反,您想检查超级用户的jobs。例如,sudo jobs 将是您要查找的命令...

请注意,这不是一个编程问题,当然也不是关于 C 的。我们有足够的低级噪音从人们的标签上发送垃圾邮件将 x86 汇编概念与 C 混淆了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-01
    • 2010-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多