Search code examples
dartdart-pub

getting process ID of a pub serve to then kill that thread/process


So when I run my Polymer Dart application, i use pub serve and the serve is created and served. It will stay running until until i break out of it. I was curious if there is a way to programmatically stop it.

One of the options I was looking at was looking at the running processes and then killing the pub serve process.

I was not sure though how i would get the process id to kill it, or unless there was another option.

Maybe someone has an even better approach to shutdown pub serve on the machine automatically, as a form of cleanup?

The issue I have noticed is that if i get the running proceesses, i only see "cmd" as a process so that isnt the best determining factor.

I was not sure if there was a way via pub on serve to get its process if, if it set a flag or global of sorts I could leverage


Solution

  • This is not a Dart or Pub question really, it's a Windows, MacOS, Linux etc. shell process control question.

    The question is more suited to Stack Exchange Superuser https://superuser.com/ I believe. You could look over there for more detailed answer ... but ... assuming you are using the windows command prompt:

    start /B starts a process in the background.

    tasklist can be used to look up running process PIDs.

    taskkill /PID kills a running process.

    You can use help <command> or search for documentation.

    I have not used these personally but it looks awkward as start /B does not give you the PID of the process it ran. Unix shells such as Bash have good facilities for running processes in the background. Windows Powershell may have better support also.