search
HomeBackend DevelopmentPHP Tutorialphp根据文件不同关闭同名进程

比如有个 a.exe 在 C:\test 和 C:\test\test 目录下,在两个目录下把a.exe都运行,然后任务管理器里面就出现了两个a.exe  怎么用php关闭,指定目录下的a.exe   比如我想关闭C:\test\test 下的运行的a.exe该怎么办   


回复讨论(解决方案)

windows不了解。

linux下,运行一个进程后都会有一个唯一的pid。可以通过一个shell脚本来运行php脚本的进程作为其子进程,运行后可以得到各自的pid,然后kill的时候直接kill相关的pid既可。

php本身也可以通过getmypid函数获取当前脚本进程pid。不过似乎是不能杀死自身进程,还是需要个master进程对来控制。

python不太会,如果是ruby的话,程序自己也能获得pid,但貌似也无法杀死自己。
最简单的方法就是用shell做主控进程。

向操作系统发出相应的命令就可以了
但遗憾的是:你做不到,因为 php 没有足够的权限

windows不了解。

linux下,运行一个进程后都会有一个唯一的pid。可以通过一个shell脚本来运行php脚本的进程作为其子进程,运行后可以得到各自的pid,然后kill的时候直接kill相关的pid既可。

php本身也可以通过getmypid函数获取当前脚本进程pid。不过似乎是不能杀死自身进程,还是需要个master进程对来控制。

pytho…… windows 下也有唯一的pid 不过主要是你不知道哪个pid是属于哪个目录下的程序,我要做的相当与是一个监控程序,监控该目录下的那个程序记录的日志情况,如有问题就关闭该目录下的那个进程,但是其他目录下又有同名的进程 

向操作系统发出相应的命令就可以了
但遗憾的是:你做不到,因为 php 没有足够的权限

你用一个单独的脚本来启动你所谓的两个不同的目录的程序,启动后可以立刻获得其pid,然后就记录下来呗。不过还是那个问题,php貌似没那个权限杀掉系统进程。

不太熟悉windows的批处理,在linux下,这个主控进程应该用shell脚本来做。它负责启动两个进程,启动后立刻记录进程pid,并且可以与哪个目录的程序关联起来。

tasklist 列出所有的进程,和相应的信息
tskill 查杀进程

更一般的
ntsd -c q -p PID 

但你肯定是不可能用运行于 web 方式下的 php 实现的
但你可以用 VC 或 VB 写个小程序间接实现
相关代码在网上有,一搜一大堆。因为这是个普遍的需求

你用一个单独的脚本来启动你所谓的两个不同的目录的程序,启动后可以立刻获得其pid,然后就记录下来呗。不过还是那个问题,php貌似没那个权限杀掉系统进程。

不太熟悉windows的批处理,在linux下,这个主控进程应该用shell脚本来做。它负责启动两个进程,启动后立刻记录进程pid,并且可以与哪个目录的程序关联起来。 那两个进程是自己手动启动,不是通过管理启动,所以没记pid

#7 给你的是 window 下的
linux 下可用 ps 获取进程列表,用 kill 杀死进程
当然还是那句话:你需要有做够的权限!web 方式下的 php 权限不够

已成功  谢谢各位 $path = array("C:\test","C:\test\test");
exec("wmic process where name='a.exe' get executablepath,processid", $result, $return);
if($return != 0)
return;
foreach ($result as $rows)
{
$data = preg_split("/ +/", $rows);
if(in_array($data[0],$path))
{
system("ntsd -c q -p ".$data[1], $return1);
if($return1 == 0)
echo "close success";
else
echo "close failed";
}
}
?>

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

How to make PHP applications fasterHow to make PHP applications fasterMay 12, 2025 am 12:12 AM

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

PHP Performance Optimization Checklist: Improve Speed NowPHP Performance Optimization Checklist: Improve Speed NowMay 12, 2025 am 12:07 AM

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

PHP Dependency Injection: Improve Code TestabilityPHP Dependency Injection: Improve Code TestabilityMay 12, 2025 am 12:03 AM

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

PHP Performance Optimization: Database Query OptimizationPHP Performance Optimization: Database Query OptimizationMay 12, 2025 am 12:02 AM

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft