比如有个 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";
}
}
?>

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

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.

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

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

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

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

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.

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


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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
The most popular open source editor

WebStorm Mac version
Useful JavaScript development tools

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
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
