| 1. |
Solve : how to Get PID.....!!? |
|
Answer» how can we get PID of running batch file.....? can anyone help me on this topic...? pls it's very urgent.......!! help me......!!in batch, you can use tasklist to display your batch file's PID. eg Code: [Select]tasklist /FI "IMAGENAME eq yourbatch.bat " /NH you will then need a for loop to parse out the correct fields... aren't "urgent" batch questions usually homework?maybe he did write a sysadmin batch and tried running it, but it hangs, so he needs to find PID to kill it? for whatever reasons he needs to do that, let's just give him the benefit of the doubt. btw, just curious, does schools nowadays teach DOS batching?Quote btw, just curious, does schools nowadays teach DOS batching? They certainly do. Quite a lot teach QBasic as well. They are included in the OS, no extra licences to buy, and they do enable the learning of many programming concepts. Quote from: contrex on July 04, 2007, 02:45:37 AM Quotethanks. I usually thought most schools would start with C/C++ for teaching programming concepts, SINCE its very close to the interaction with the OS, ie memory manipulation etc..DOS/QBASIC does not teach programming concepts, IMO.Quote from: ghostdog74 on July 04, 2007, 03:14:12 AMbtw, just curious, does schools nowadays teach DOS batching? [DOS/QBASIC does not teach programming concepts, IMO. That's rather snooty. Perhaps you would care to elaborate, although we would be getting a liitle OT I guess. I wrote "many" programming concepts. (not all, by any means) Learning to program in ***any*** language, assembler, FORTH, SMALLTALK, C, Python, APL, BCPL, batch, is going to give the student some experience in dealing with fundamental concepts of programming. I started with BASIC in the 1980s and it certainly was a good foundation when I later went on to use Pascal, C and Fortran. I have taught classes of students using QBasic, and many of the more apt students went on to study computer science at a higher level. Quote Computer Programming-Basic I http://www.flvs.net/students_parents/VSACourseDetail.php?CourseID=43 Dartmouth BASIC was DEVELOPED in the 1960s to ***introduce*** students to programming concepts. Of course, QBasic is more or less a "toy" language compared to more advanced languages such as C, C++ etc, but (I hope you will forgive me for saying this) I am afraid your comment reveals more about your pride and vanity than it does about your knowledge. Quote from: contrex on July 04, 2007, 03:26:07 AM That's rather snooty. Perhaps you would care to elaborate, although we would be getting a liitle OT I guess.my little "IMO" thing sure INCURRED your "wrath" didn't it. You may be right, DOS/QBASIC does provide you basic concepts, but that's just it. Programming concepts entails alot more of other stuffs, such as OO, bits/bytes manipulation, data types eg int,float, longs, interfacing with the OS/hardware, complex maths , memory management/manipulations, algorithms, spaghetti codes, etc you name it. DOS/QBASIC just doesn't make it in some of these areas. Like I already said, its just IMO. So no need to get agitated. Before getting real OT, i will stop here. i'v run 2 java file so that TASKLIST option is showing two image Name (java.exe) and different PID (like as 2460 & 3789) now suppose if i want to do stop one (java.exe) whose PID is 2460. then how could i recognized that i'v closed java.exe file of a particulare PID (2460)......? pls let me know help me Best Regards AshutoshQuote from: toshashu123 on July 04, 2007, 04:17:49 AM i'v run 2 java file so that TASKLIST option is showing two image Name (java.exe) and different PID (like as 2460 & 3789) now suppose if i want to do stop one (java.exe) whose PID is 2460. then how could i recognized that i'v closed java.exe file of a particulare PID (2460)......? Run tasklist again, and check that PID 2460 is gone if the java.exe running and u type TASKLIST again and again then it shows same PID for that particular image name it doesnt change. It does only change in case of another java.exe file is runDear All Members, i'm running batch file(start.bat) which run my java aaplication and this batch file stored at C:\ABC\XYZ\start.bat with PID like as 1792 and another batch file with same name run from this location C:\CMD\MNC\start.bat with PID like as 8967 and another batch file with same name run from this location C:\JKL\GHI\start.bat with PID like as 4356 now i make another batch file (kill.bat) and stored at each location. Now i run kill.bat from ( C:\CMD\MNC\kill.bat ) this location. my question is this that how could i found the PID of start.bat which is run from this location (C:\CMD\MNC\start.bat) and kill this process by KILL.bat file.....? If anybody help me. please revert back to me. I'v been tried two file that is KILL_FIRST.bat and KILL_LAST.bat but didnot get success. KILL_FIRST.bat @echo off REM **** KILL_FIRST.BAT **** set TASKNAME=java.exe SETLOCAL ENABLEDELAYEDEXPANSION echo Task list before KILL... set TASKTOTAL=0 for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do ( set /A TASKTOTAL=!TASKTOTAL!+1 echo [Task !TASKTOTAL! is "%%A %%B"] ) echo [Task %TASKTOTAL% is last] echo IF START if %TASKTOTAL%==0 goto :eof set TASKCOUNT=0 for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do ( set /A TASKCOUNT=!TASKCOUNT!+1 if !TASKCOUNT!==1 taskkill.exe /F /PID %%B ) echo Task list after KILL... set TASKTOTAL=0 for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do ( set /A TASKTOTAL=!TASKTOTAL!+1 echo [Task !TASKTOTAL! is "%%A %%B"] ) echo LOOP-3 END echo [Task %TASKTOTAL% is last] KILL_LAST.bat @echo off REM **** KILL_LAST.BAT **** set TASKNAME=java.EXE SETLOCAL ENABLEDELAYEDEXPANSION echo Task list before KILL_LAST... set TASKTOTAL=0 for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do ( set /A TASKTOTAL=!TASKTOTAL!+1 echo [Task !TASKTOTAL! is "%%A %%B"] ) echo [Task %TASKTOTAL% is last] if %TASKTOTAL%==0 goto :eof set TASKCOUNT=0 for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do ( set /A TASKCOUNT=!TASKCOUNT!+1 if !TASKCOUNT!==!TASKTOTAL! taskkill.exe /F /PID %%B ) echo Task list after KILL_LAST... set TASKTOTAL=0 for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do ( set /A TASKTOTAL=!TASKTOTAL!+1 echo [Task !TASKTOTAL! is "%%A %%B"] ) echo [Task %TASKTOTAL% is last] Can anyone help me on this topic pls..........? Best Regards AshutoshOK, this is the third place you've asked that question. Stop now.This might be a waste of time, but if it rids us of the nuisance it will be worth while... Quote my question is this that how could i found the PID of start.bat which is run from this location (C:\CMD\MNC\start.bat) and kill this process by KILL.bat file.....? Here are DETAILED INSTRUCTIONS. Use the knowledge gained to write batch file or perform task from command line. 1. Plant an unique identifier into each start.bat. Add a line to each start.bat such as title "identifier999" (or some other title meaningful to you) 2. Now you can filter Tasklist output by window title 3. Use /v switch to get verbose output which includes window titles. 4. Use /NH switch to hide header lines. 5. Use /FI switch to apply filter "WINDOWTITLE eq indentifier999" 6. It is now a trivial task to extract the PID (it is the second token using space as delimiter) 7. Now use taskkill /PID NNNN to remove the task. Example... c:\>tasklist /v /NH /FI "WINDOWTITLE eq identifier999" cmd.exe 3916 Console 0 2,396 K Running PUPP-C92F25ED23\Mike 0:00:00 identifier999 Here PID is 3916 start1.bat @echo off title START_ONE pause start2.bat @echo off title START_TWO pause kill_start1.bat for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "windowtitle eq START_ONE"') do taskkill.exe /PID %%B kill_start2.bat for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "windowtitle eq START_TWO"') do taskkill.exe /PID %%B |
|