执行shell脚本系统()返回256是什么意思呢? [英] Executing shell script with system() returns 256. What does that mean?

查看:1945
本文介绍了执行shell脚本系统()返回256是什么意思呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个shell脚本,软启动HAProxy的(反向代理)。从壳工程执行脚本。但我想一个守护进程来执行脚本。那好好尝试的工作。系统()返回256.我不知道是什么这可能意味着

I've written a shell script to soft-restart HAProxy (reverse proxy). Executing the script from the shell works. But I want a daemon to execute the script. That doens't work. system() returns 256. I have no clue what that might mean.

#!/bin/sh
# save previous state
mv /home/haproxy/haproxy.cfg /home/haproxy/haproxy.cfg.old
mv /var/run/haproxy.pid /var/run/haproxy.pid.old

cp /tmp/haproxy.cfg.new /home/haproxy/haproxy.cfg
kill -TTOU $(cat /var/run/haproxy.pid.old)
if haproxy -p /var/run/haproxy.pid -f /home/haproxy/haproxy.cfg; then
  kill -USR1 $(cat /var/run/haproxy.pid.old)
  rm -f /var/run/haproxy.pid.old
  exit 1
else
  kill -TTIN $(cat /var/run/haproxy.pid.old)
  rm -f /var/run/haproxy.pid
  mv /var/run/haproxy.pid.old /var/run/haproxy.pid
  mv /home/haproxy/haproxy.cfg /home/haproxy/haproxy.cfg.err
  mv /home/haproxy/haproxy.cfg.old /home/haproxy/haproxy.cfg
  exit 0
fi

HAProxy的与用户的haproxy执行。我的守护进程有它自己的用户了。无论使用sudo运行。

HAProxy is executed with user haproxy. My daemon has it's own user too. Both run with sudo.

任何提示?

推荐答案

据的这个的, Perl的系统()返回乘以256。因此,它实际上与 1 退出退出值。这似乎<一个href=\"http://stackoverflow.com/questions/808541/any-benefit-in-using-wexitstatus-macro-in-c-over-division-by-256-on-exit-status\">this发生用C太。

According to this and that, Perl's system() returns exit values multiplied by 256. So it's actually exiting with 1. It seems this happens in C too.

这篇关于执行shell脚本系统()返回256是什么意思呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆