display the file descriptors of a process using python [closed]
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
How can I display the open file descriptors of a process in linux using python script? I tried using
readlink /proc/PID/fd/*
in python script but I am getting error.
/bin/sh: 2: /fd/*: not found
I think subprocess module will not give error. How will I use it to remove error if possible to display file descriptors?
Code:
import os
p=os.popen("pgrep -x vlc")
q=p.read()
print("Process ID of VLC : ",q)
process= os.popen("readlink /proc/"+str(q)+"/fd/*")
s=process.read()
print(s)
python proc file-descriptors vlc
closed as off-topic by Romeo Ninov, Goro, maulinglawns, Thomas, RalfFriedl Sep 23 at 12:02
- This question does not appear to be about Unix or Linux within the scope defined in the help center.
add a comment |Â
up vote
0
down vote
favorite
How can I display the open file descriptors of a process in linux using python script? I tried using
readlink /proc/PID/fd/*
in python script but I am getting error.
/bin/sh: 2: /fd/*: not found
I think subprocess module will not give error. How will I use it to remove error if possible to display file descriptors?
Code:
import os
p=os.popen("pgrep -x vlc")
q=p.read()
print("Process ID of VLC : ",q)
process= os.popen("readlink /proc/"+str(q)+"/fd/*")
s=process.read()
print(s)
python proc file-descriptors vlc
closed as off-topic by Romeo Ninov, Goro, maulinglawns, Thomas, RalfFriedl Sep 23 at 12:02
- This question does not appear to be about Unix or Linux within the scope defined in the help center.
worth adding the remaining output from the script, e.g. that "Process ID of VLC : " output.
â steve
Sep 22 at 19:12
Process ID will keep changing everytime vlc is opened. So we can assume output as "Process ID of VLC : 12699"
â ironman
Sep 22 at 19:17
Surely popen is for opening a single file. Use of * is bogus ?
â steve
Sep 22 at 19:49
You are right but code is giving error. When I run only the "readlink /proc/12699/fd/*" I am not getting error.
â ironman
Sep 22 at 19:50
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
How can I display the open file descriptors of a process in linux using python script? I tried using
readlink /proc/PID/fd/*
in python script but I am getting error.
/bin/sh: 2: /fd/*: not found
I think subprocess module will not give error. How will I use it to remove error if possible to display file descriptors?
Code:
import os
p=os.popen("pgrep -x vlc")
q=p.read()
print("Process ID of VLC : ",q)
process= os.popen("readlink /proc/"+str(q)+"/fd/*")
s=process.read()
print(s)
python proc file-descriptors vlc
How can I display the open file descriptors of a process in linux using python script? I tried using
readlink /proc/PID/fd/*
in python script but I am getting error.
/bin/sh: 2: /fd/*: not found
I think subprocess module will not give error. How will I use it to remove error if possible to display file descriptors?
Code:
import os
p=os.popen("pgrep -x vlc")
q=p.read()
print("Process ID of VLC : ",q)
process= os.popen("readlink /proc/"+str(q)+"/fd/*")
s=process.read()
print(s)
python proc file-descriptors vlc
python proc file-descriptors vlc
asked Sep 22 at 19:09
ironman
1116
1116
closed as off-topic by Romeo Ninov, Goro, maulinglawns, Thomas, RalfFriedl Sep 23 at 12:02
- This question does not appear to be about Unix or Linux within the scope defined in the help center.
closed as off-topic by Romeo Ninov, Goro, maulinglawns, Thomas, RalfFriedl Sep 23 at 12:02
- This question does not appear to be about Unix or Linux within the scope defined in the help center.
worth adding the remaining output from the script, e.g. that "Process ID of VLC : " output.
â steve
Sep 22 at 19:12
Process ID will keep changing everytime vlc is opened. So we can assume output as "Process ID of VLC : 12699"
â ironman
Sep 22 at 19:17
Surely popen is for opening a single file. Use of * is bogus ?
â steve
Sep 22 at 19:49
You are right but code is giving error. When I run only the "readlink /proc/12699/fd/*" I am not getting error.
â ironman
Sep 22 at 19:50
add a comment |Â
worth adding the remaining output from the script, e.g. that "Process ID of VLC : " output.
â steve
Sep 22 at 19:12
Process ID will keep changing everytime vlc is opened. So we can assume output as "Process ID of VLC : 12699"
â ironman
Sep 22 at 19:17
Surely popen is for opening a single file. Use of * is bogus ?
â steve
Sep 22 at 19:49
You are right but code is giving error. When I run only the "readlink /proc/12699/fd/*" I am not getting error.
â ironman
Sep 22 at 19:50
worth adding the remaining output from the script, e.g. that "Process ID of VLC : " output.
â steve
Sep 22 at 19:12
worth adding the remaining output from the script, e.g. that "Process ID of VLC : " output.
â steve
Sep 22 at 19:12
Process ID will keep changing everytime vlc is opened. So we can assume output as "Process ID of VLC : 12699"
â ironman
Sep 22 at 19:17
Process ID will keep changing everytime vlc is opened. So we can assume output as "Process ID of VLC : 12699"
â ironman
Sep 22 at 19:17
Surely popen is for opening a single file. Use of * is bogus ?
â steve
Sep 22 at 19:49
Surely popen is for opening a single file. Use of * is bogus ?
â steve
Sep 22 at 19:49
You are right but code is giving error. When I run only the "readlink /proc/12699/fd/*" I am not getting error.
â ironman
Sep 22 at 19:50
You are right but code is giving error. When I run only the "readlink /proc/12699/fd/*" I am not getting error.
â ironman
Sep 22 at 19:50
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
You'll have to strip the trailing newline from q
, ex. q = q.strip()
.
Also, you'll have to think through what happens if there's more than one vlc
running.
I'm curious to know , how did you find that? I spent lot of time in figuring out this error. But all effort was in vain.
â ironman
Sep 23 at 4:53
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
You'll have to strip the trailing newline from q
, ex. q = q.strip()
.
Also, you'll have to think through what happens if there's more than one vlc
running.
I'm curious to know , how did you find that? I spent lot of time in figuring out this error. But all effort was in vain.
â ironman
Sep 23 at 4:53
add a comment |Â
up vote
2
down vote
accepted
You'll have to strip the trailing newline from q
, ex. q = q.strip()
.
Also, you'll have to think through what happens if there's more than one vlc
running.
I'm curious to know , how did you find that? I spent lot of time in figuring out this error. But all effort was in vain.
â ironman
Sep 23 at 4:53
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
You'll have to strip the trailing newline from q
, ex. q = q.strip()
.
Also, you'll have to think through what happens if there's more than one vlc
running.
You'll have to strip the trailing newline from q
, ex. q = q.strip()
.
Also, you'll have to think through what happens if there's more than one vlc
running.
edited Sep 22 at 20:52
answered Sep 22 at 20:42
mosvy
1,752110
1,752110
I'm curious to know , how did you find that? I spent lot of time in figuring out this error. But all effort was in vain.
â ironman
Sep 23 at 4:53
add a comment |Â
I'm curious to know , how did you find that? I spent lot of time in figuring out this error. But all effort was in vain.
â ironman
Sep 23 at 4:53
I'm curious to know , how did you find that? I spent lot of time in figuring out this error. But all effort was in vain.
â ironman
Sep 23 at 4:53
I'm curious to know , how did you find that? I spent lot of time in figuring out this error. But all effort was in vain.
â ironman
Sep 23 at 4:53
add a comment |Â
worth adding the remaining output from the script, e.g. that "Process ID of VLC : " output.
â steve
Sep 22 at 19:12
Process ID will keep changing everytime vlc is opened. So we can assume output as "Process ID of VLC : 12699"
â ironman
Sep 22 at 19:17
Surely popen is for opening a single file. Use of * is bogus ?
â steve
Sep 22 at 19:49
You are right but code is giving error. When I run only the "readlink /proc/12699/fd/*" I am not getting error.
â ironman
Sep 22 at 19:50