Showing posts with label process. Show all posts
Showing posts with label process. Show all posts

Saturday, May 8, 2010

Windows process/service killing, Get process Id using Java

Recently I came across the situation where I need to automate the finding process id, and kill some windows services based on the value provided in the dashboard. You can read the values at certain interval and complete the actions like killing services, or monitor the process ids, or get list of processes start with same prefix.., hope below helps..


Killing the Service using Java; example code is below –

log.info("Forcefully Killing Services - Taskkill command length: "+arg.length);

String cmd = "cmd.exe /c taskkill /s "+ +" /fi \"services eq "+ +"\" /f >d:\\temp\\log\\output.txt";

//e.g. taskkill /f /im notepad.exe or taskkill /PID 827

log.info("Command to Execute: "+cmd);

//execute the command
Process process = Runtime.getRuntime().exec(cmd);

If you want to get the process id of the service -
log.info("Getting PID - Tasklist command length: "+arg.length);

String cmd = "cmd.exe /c tasklist /s "+ +" /svc /fi \"services eq "+ +"\">d:\\tdp\\log\\output.txt";

//here service name can be prefix, like note*, it will list all the services which starts with note prefix.

log.info("Command to Execute: "+cmd);

Process process = Runtime.getRuntime().exec(cmd);

//to do a synchronous action till you get the result
int exitVal = process.waitFor();

//to check success or failure
log.info("Process exitValue: " + exitVal);

- You can take different actions on the services, and there are other task commands which can be automated using the above steps. However, its not much advisable to use Runtime.getRuntime().exec(). As in case of success or failure you will not always get correct results, sometimes it just stay in the hanging stage. And to read the output, it requires to read the process.getErrorStream(); or you can just move the output to some txt as I am doing in above example...

Wednesday, December 30, 2009

Can you differentiate corrective and preventive actions for process evaluation???

Evaluation of any process unforgettably includes the corrective and preventive action. Corrective action as the name suggest something you are correcting after you found existing nonconformity or defect, and preventing action is one that action taken to eliminate the cause of a possible nonconformity, defect or potential hole in the system.

Today majority companies follows a standardize procedure for software configuration management, e.g. ISO 9001:2000 for quality assurance. This procedure includes corrective and preventive actions and revises their process tracking system in order to improve the quality of their deliverable. Preventive action includes reviews, software validations and verification, quality management system review, and kind of more about statistical result driven actions. As process passed through particular obstacle, concern person review the cause of problem and provide their feed back in order to update your procedure and makes sure that the process will prevent reoccurrence in the future for the same kind of situation. For the corrective action, once you found the problem you will make some steps to correct your work done.

This same method is applicable to wide area of functional process, whether it’s manufacturing process, software development, or other routine procedures in different firms.

Reference: Software Engineering: A Practitioner's Approach, by Roger S Pressman