Reputation: 3318
I am using R in my Ubuntu machine with latest configuration
In R, I get below result:
> read.fwf(pipe('ps -ef | grep /var/lib/docker/'), width = 60)
V1
1 root 29155 29151 0 11:18 pts/0 00:00:00 sh -c ps -ef
2 root 29157 29155 0 11:18 pts/0 00:00:00 grep /var/li
However in Ubuntu console I get different result
ps -ef | grep /var/lib/docker/
root 29150 2509 0 11:17 pts/0 00:00:00 grep --color=auto /var/lib/docker/
I wanted R to fetch PID
of /var/lib/docker/
, which is according to Ubuntu 2509
Can anyone help me understand why I am getting different result and how to fetch the PID number correctly?
Thanks,
Upvotes: 1
Views: 44
Reputation: 270055
Use ps()
in the ps package. This function outputs a data.frame with the process id information.
library(ps)
pid_df <- ps()
pid_df$pid[grep("docker", pid_df$name)]
or in one line:
subset(ps(), grep("docker", name))$pid
Upvotes: 0