display the file descriptors of a process using python [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite
1












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)









share|improve this question













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.
If this question can be reworded to fit the rules in the help center, please edit the question.












  • 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















up vote
0
down vote

favorite
1












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)









share|improve this question













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.
If this question can be reworded to fit the rules in the help center, please edit the question.












  • 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













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





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)









share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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.
If this question can be reworded to fit the rules in the help center, please edit the question.




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.
If this question can be reworded to fit the rules in the help center, please edit the question.











  • 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










  • 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











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.






share|improve this answer






















  • 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

















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.






share|improve this answer






















  • 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














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.






share|improve this answer






















  • 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












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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








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
















  • 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


Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?