【发布时间】: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 install 或sudo /etc/init.d/fhttpd.init start,jobs 什么都不会显示。事实上,服务器运行正常。我只是不知道它是如何工作的,因为我在 /etc/init.d/fhttpd.init 中使用了&。
我不知道为什么我不能在makefile 中使用“工作”。在这种情况下,我怎样才能找回后台程序。
【问题讨论】:
-
init 脚本在不同的 shell 中运行,因此它的作业在您的 shell 中不可见。您需要使用不同的工具(例如
pgrep)来验证服务器是否正在运行。 -
你知道我想看看它的状态,怎么切换吗?
-
您无法访问启动服务器的 shell。它不再运行了。我希望
fhttpd status会做点什么 -
谢谢,这是一个让我们以某种方式使服务器崩溃的项目。如何查看它是否崩溃?
-
尝试读取服务器日志
标签: shell makefile init ampersand