Reputation:
I'm working on a Windows machine and would like to get the list of all running processes directly from R (basically process id and path to the program which is running).
I know Sys.getpid()
gets me the process id of the current R process but does there also exist something to get me all processes running on the machine as I would get in Linux with top
or ps -x
Upvotes: 3
Views: 3056
Reputation: 121568
You can use tasklist
:
system2( 'tasklist' , stdout = TRUE )
[1] ""
[2] "Nom de l'image PID Nom de la sessio Num‚ro de s Utilisation "
[3] "========================= ======== ================ =========== ============"
[4] "System Idle Process 0 Services 0 24 Ko"
EDIT to get the R process:
grep("^rsession",readLines(textConnection(system('tasklist',intern=TRUE))),value=TRUE)
[1] "rsession.exe 6772 Console 1 387,420 Ko"
[2] "rsession.exe 7984 Console 1 48,436 Ko"
[3] "rsession.exe 1272 Console 1 80,572 Ko"
Upvotes: 6