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

kesion系统做网站教程建设银行网站首页打

kesion系统做网站教程,建设银行网站首页打,网站截图怎么做,163企业邮箱怎么开通注册一#xff0c;system()理解 功能#xff1a;system()函数调用“/bin/sh -c command”执行特定的命令#xff0c;阻塞当前进程直到command命令执行完毕 原型#xff1a; int system(const char *command); 返回值#xff1a; 如果无法启动shell运行命令#xff0c;system将… 一system()理解 功能system()函数调用“/bin/sh -c command”执行特定的命令阻塞当前进程直到command命令执行完毕 原型 int system(const char *command); 返回值 如果无法启动shell运行命令system将返回127出现不能执行system调用的其他错误时返回-1。如果system能够顺利执行返回那个命令的退出码。 说明 man帮助        #include stdlib.h        int system(const char *command); DESCRIPTION         system()  executes a command specified in command by calling /bin/sh -c         command, and returns after the command has been completed.  During exe-         cution  of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT         will be ignored. RETURN VALUE         The value returned is -1 on  error  (e.g.   fork(2)  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).        If the value of command is NULL, system() returns non-zero if the shell         is available, and zero if not.        system() does not affect the wait status of any other children. 二system()函数原理 system函数执行时会调用fork、execve、waitpid等函数。 linux版system函数的源码 int system(const char * cmdstring){pid_t pid;int status;if(cmdstring NULL){ return (1);}if((pid fork())0){status -1;}else if(pid 0){execl(/bin/sh, sh, -c, cmdstring, (char *)0);_exit(127); //子进程正常执行则不会执行此语句}else{while(waitpid(pid, status, 0) 0){ if(errno ! EINTER){status -1;break;}}}return status;} 函数说明  system()会调用fork()产生子进程由子进程来调用/bin/sh-c string来执行参数string字符串所代表的命令此命令执行完后随即返回原调用的进程。 在调用system()期间SIGCHLD 信号会被暂时搁置SIGINT和SIGQUIT 信号则会被忽略。  返回值  -1:出现错误   0:调用成功但是没有出现子进程   0:成功退出的子进程的id  如果system()在调用/bin/sh时失败则返回127其他失败原因返回-1。若参数string为空指针(NULL)则返回非零值。如果system()调用成功则最后会返回  执行shell命令后的返回值但是此返回值也有可能为 system()调用/bin/sh失败所返回的127因此最好能再检查errno 来确认执行成功。  附加说明  在编写具有SUID/SGID权限的程序时请勿使用system()system()会继承环境变量通过环境变量可能会造成系统安全的问题。 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 ! status  2WIFEXITED(status)为真  30 WEXITSTATUS(status)  注意  根据以上分析当shell脚本不存在、没有执行权限等场景下时以上前2个条件仍会成立此时WEXITSTATUS(status)为127126等数值。  所以我们在shell脚本中不能将127126等数值定义为返回值否则无法区分中是shell的返回值还是调用shell脚本异常的原因值。shell脚本中的返回值最好多1开始递增。 示例程序 #include stdio.h #include unistd.h #include stdlib.h#define EXIT_ERR(m) \ do\ {\perror(m);\exit(EXIT_FAILURE);\ }\ while (0);\int main(void) {int status ;status system(ls -l|wc -l);if(status -1){EXIT_ERR(system error);}else{if(WIFEXITED(status)){if(WEXITSTATUS(status) 0)printf(run command successful\n);elseprintf(run command fail and exit code is %d\n,WEXITSTATUS(status));}elseprintf(exit status %d\n,WEXITSTATUS(status));}return 0; } 结果
http://wiki.neutronadmin.com/news/147851/

相关文章:

  • 界面设计最好的网站电商网站怎么做聚合
  • 什么叫利用网站做蜘蛛池双语版网站引导页
  • 高校网站建设的意义网站模版属于侵权吗
  • 网站建设四个阶段的流程网站建设销售问你告诉我怎么制作
  • 网站建设企网站建设背景分析
  • 常州建设网站代理商网站做直播需要什么资质
  • 开封网站开发财经网站源码 织梦
  • 深圳网站建设模板乐云seo虎丘做网站价格
  • 济南网站开发公司排名个人手机网站大全
  • 中职电子商务网站建设与维护考试题自己做的网址如何推广
  • 农村学校资源网站建设与研究广告营销策划公司
  • 网站怎么做身份验证哪里建设网站比较好
  • 鞍山外国网站制作网站开发 软件开发
  • 网站做优化有什么好处wordpress用户登陆
  • wordpress爱视频优化方案英语必修二电子版
  • 网站建设开发熊掌号阿里巴巴电子商务网站建设目的
  • 唐山网站制作方案线上网站开发系统流程图
  • 网站优化个人工作室帮人管理网站做淘宝客
  • p2p网站开发方法南京app外包
  • 北京建设管理有限公司官网seo关键词排名优
  • 自然堂官方网站建设北京做网站那家好
  • 零食网站色调搭配怎麽做北京怎样做网站推广
  • 上海跨境电商网站制作佛山网站优化推广方案
  • 永康网站开发公司公司网站推广技巧
  • 宝塔怎么创建网站手机网站推荐几个
  • 一级域名免费网站怎么申请成都网站推广营销设计
  • 企业门户网站静态模板wordpress设计
  • 齐齐哈尔企业网站排名优化wordpress忘记账号密码
  • 自媒体平台网站开发杭州电子商务网站建设公司
  • 苏州市优化网站推广哪家好游戏网站风控怎么做