简体   繁体   English

使用PHP终止Shell脚本

[英]Terminate shell script using PHP

I'm trying to terminate a shell script using PHP code. 我正在尝试使用PHP代码终止Shell脚本。

I have created a shell script foo.sh which calls a PHP file 我创建了一个shell脚本foo.sh ,它调用一个PHP文件

#! /bin/bash

cd /var/www/html/test
php test.php

Following is test.php 以下是test.php

<?php
  exec('exit 0');
?>

For some reason the shell script is not exiting. 由于某种原因,shell脚本没有退出。

Your exit(0) in PHP will terminate process with PHP itself, and not parent process (if any). PHP中的exit(0)将终止PHP本身的进程,而不终止父进程(如果有)。 To terminate your bash script, you will need to find it's pid via ps and grep , or, alternatively, use killall : 要终止您的bash脚本,您将需要通过psgrep找到它的pid,或者使用killall

system('killall foo.sh');

-in PHP -在PHP中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM