当前位置: 首页 > news >正文

肇庆市住房和城乡建设局网站咨询公司资质要求

肇庆市住房和城乡建设局网站,咨询公司资质要求,服装网站建设什么公司好,桓台新城建设有限公司网站1、先统一两个说法#xff1a;#xff08;1#xff09;system返回值#xff1a;指调用system函数后的返回值#xff0c;比如上例中status为system返回值#xff08;2#xff09;shell返回值#xff1a;指system所调用的shell命令的返回值#xff0c;比如上例中#x…1、先统一两个说法1system返回值指调用system函数后的返回值比如上例中status为system返回值2shell返回值指system所调用的shell命令的返回值比如上例中test.sh中返回的值为shell返回值。2、如何正确判断test.sh是否正确执行仅判断status是否0或者仅判断status是否!-1?都错3、man中对于system的说明RETURN VALUE        The value returned is -1 on error (e.g.  fork() failed), and the return        status  of  the command otherwise.  This latter return status is in the        format specified in wait(2).  Thus, the exit code of the  command  will        be  WEXITSTATUS(status).   In  case  /bin/sh could not be executed, the        exit status will be that of a command that does exit(127).看得很晕吧system函数对返回值的处理涉及3个阶段阶段1创建子进程等准备工作。如果失败返回-1。阶段2调用/bin/sh拉起shell脚本如果拉起失败或者shell未正常执行结束参见备注1原因值被写入到status的低8~15比特位中。system的man中只说明了会写了127这个值但实测发现还会写126等值。阶段3如果shell脚本正常执行结束将shell返回值填到status的低8~15比特位中。备注1只要能够调用到/bin/sh并且执行shell过程中没有被其他信号异常中断都算正常结束。比如不管shell脚本中返回什么原因值是0还是非0都算正常执行结束。即使shell脚本不存在或没有执行权限也都算正常执行结束。如果shell脚本执行过程中被强制kill掉等情况则算异常结束。如何判断阶段2中shell脚本是否正常执行结束呢系统提供了宏WIFEXITED(status)。如果WIFEXITED(status)为真则说明正常结束。如何取得阶段3中的shell返回值你可以直接通过右移8bit来实现但安全的做法是使用系统提供的宏WEXITSTATUS(status)。由于我们一般在shell脚本中会通过返回值判断本脚本是否正常执行如果成功返回0失败返回正数。所以综上判断一个system函数调用shell脚本是否正常结束的方法应该是如下3个条件同时成立1-1 ! status2WIFEXITED(status)为真30 WEXITSTATUS(status)注意根据以上分析当shell脚本不存在、没有执行权限等场景下时以上前2个条件仍会成立此时WEXITSTATUS(status)为127126等数值。所以我们在shell脚本中不能将127126等数值定义为返回值否则无法区分中是shell的返回值还是调用shell脚本异常的原因值。shell脚本中的返回值最好多1开始递增。判断shell脚本正常执行结束的健全代码如下[cpp] view plaincopy #include stdio.h   #include stdlib.h   #include sys/wait.h   #include sys/types.h      int main()   {       pid_t status;             status  system(./test.sh);          if (-1  status)       {           printf(system error!);       }       else       {           printf(exit status value  [0x%x]\n, status);              if (WIFEXITED(status))           {               if (0  WEXITSTATUS(status))               {                   printf(run shell script successfully.\n);               }               else               {                   printf(run shell script fail, script exit code: %d\n, WEXITSTATUS(status));               }           }           else           {               printf(exit status  [%d]\n, WEXITSTATUS(status));           }       }          return 0;   }   WIFEXITED(stat_val) Evaluates to a non-zero value if status was returned for a child process that terminated normally. WEXITSTATUS(stat_val) If the value of WIFEXITED(stat_val) is non-zero, this macro evaluates to the low-order 8 bits of the status argument that the child process passed to _exit() or exit(), or the value the child process returned from main().言归正传下面这段代码则会导致程序system调用总是返回-1[cpp] view plaincopy #include stdio.h   #include stdlib.h   #include signal.h      int main(int argc ,char *argv[])   {       signal(SIGCHLD,SIG_IGN);       int status  system(ls -l);       if(status  -1)        {              printf(system fork faild !\n);       }          else         {              printf(exit status value  [0x%x]\n, status);                if (WIFEXITED(status))             {                  if (0  WEXITSTATUS(status))                 {                      printf(run shell script successfully.\n);                 }                  else                 {                      printf(run shell script fail, script exit code: %d\n, WEXITSTATUS(status));                 }              }              else             {                  printf(exit status  [%d]\n, WEXITSTATUS(status));             }          }          return 0;   }
http://www.yutouwan.com/news/476978/

相关文章:

  • 做跨境网站saas建站工具
  • 手机快速建站wordpress 指定
  • 怎么查一个网站的备案信息iis网站建设
  • 电影网站怎么建设怎么套用网站模板
  • 榆林做网站多少钱义乌外贸建网站
  • 移动端网站怎么提交一个软件开发团队需要哪些人
  • 网站公司倒闭一级页面的网站怎么做
  • 网站建设进度计划山西做网站价格
  • 新型h5网站建设新泰网络推广公司
  • 广东建设工程网站移动网站开发认证
  • 墙绘网站建设怎么修改网站网页的背景图片
  • 辽宁省住房和城乡建设厅网站上不去必应搜索引擎下载
  • 平台网站建设iis7.5添加php网站
  • 平谷网站建设服务asp 微信网站
  • 做视频广告在哪个网站能够赚钱wordpress ip地址修改
  • 图片网站怎样选择虚拟主机社区网站建设费用
  • 六安网站建设定制建设视频网站设计意义
  • 用.net做网站好_还是用php电网站建设用地赔偿
  • 做网站哪里有莱芜网络推广
  • 个人外贸网站建设网站建好怎么发布
  • 网站开发多少钱一个合肥网站营销
  • 如何做自己的大淘客网站html个人源码
  • 古镇建网站公司WordPress rss连接
  • 所有网站的分辨率成都网站建设推来客
  • 如何查看网站备案信息吗做会员卡的网站在线制作
  • 江阴做网站的地方桐乡市住房建设局网站
  • 外贸网站增加外链方法青县网站建设公司
  • 增城市网站建设改则网站建设
  • 网站开发背景知识论文安徽展览展示公司排名
  • 网站降权查询工具wordpress找不到后台