Get python process ID for a flask web site and/or port number?

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











up vote
0
down vote

favorite












I have some web applications that I wrote with python flask. I know which port I started each one on and each was started using nohup. Each one was started with something like nohup python mywebapp.py &



When I look at my processes with ps, I only see something like



36697 ? 60-21:36:16 python
36971 ? 63-19:11:43 python
37038 ? 65-06:57:22 python
37312 ? 54-23:33:16 python
37442 ? 54-09:14:57 python
37716 ? 47-19:45:17 python
68019 ? 00:29:24 python
146568 ? 00:20:57 python
146699 ? 00:17:08 python
150622 ? 00:32:20 python


If I need to stop one particular web application, how can I get from a port number back to a python process id so that I can kill the process?







share|improve this question



















  • where does the port number get specified when you start(ed) them?
    – Jeff Schaller
    Jun 26 at 16:21










  • @JeffSchaller Great question, that is specified within the python code, specifically with a call to start an app server with the flask library/framework.
    – Unknown Coder
    Jun 26 at 16:25










  • So the parameter mywebapp.py is enough to determine the port?
    – Jeff Schaller
    Jun 26 at 16:31














up vote
0
down vote

favorite












I have some web applications that I wrote with python flask. I know which port I started each one on and each was started using nohup. Each one was started with something like nohup python mywebapp.py &



When I look at my processes with ps, I only see something like



36697 ? 60-21:36:16 python
36971 ? 63-19:11:43 python
37038 ? 65-06:57:22 python
37312 ? 54-23:33:16 python
37442 ? 54-09:14:57 python
37716 ? 47-19:45:17 python
68019 ? 00:29:24 python
146568 ? 00:20:57 python
146699 ? 00:17:08 python
150622 ? 00:32:20 python


If I need to stop one particular web application, how can I get from a port number back to a python process id so that I can kill the process?







share|improve this question



















  • where does the port number get specified when you start(ed) them?
    – Jeff Schaller
    Jun 26 at 16:21










  • @JeffSchaller Great question, that is specified within the python code, specifically with a call to start an app server with the flask library/framework.
    – Unknown Coder
    Jun 26 at 16:25










  • So the parameter mywebapp.py is enough to determine the port?
    – Jeff Schaller
    Jun 26 at 16:31












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have some web applications that I wrote with python flask. I know which port I started each one on and each was started using nohup. Each one was started with something like nohup python mywebapp.py &



When I look at my processes with ps, I only see something like



36697 ? 60-21:36:16 python
36971 ? 63-19:11:43 python
37038 ? 65-06:57:22 python
37312 ? 54-23:33:16 python
37442 ? 54-09:14:57 python
37716 ? 47-19:45:17 python
68019 ? 00:29:24 python
146568 ? 00:20:57 python
146699 ? 00:17:08 python
150622 ? 00:32:20 python


If I need to stop one particular web application, how can I get from a port number back to a python process id so that I can kill the process?







share|improve this question











I have some web applications that I wrote with python flask. I know which port I started each one on and each was started using nohup. Each one was started with something like nohup python mywebapp.py &



When I look at my processes with ps, I only see something like



36697 ? 60-21:36:16 python
36971 ? 63-19:11:43 python
37038 ? 65-06:57:22 python
37312 ? 54-23:33:16 python
37442 ? 54-09:14:57 python
37716 ? 47-19:45:17 python
68019 ? 00:29:24 python
146568 ? 00:20:57 python
146699 ? 00:17:08 python
150622 ? 00:32:20 python


If I need to stop one particular web application, how can I get from a port number back to a python process id so that I can kill the process?









share|improve this question










share|improve this question




share|improve this question









asked Jun 26 at 15:57









Unknown Coder

1203




1203











  • where does the port number get specified when you start(ed) them?
    – Jeff Schaller
    Jun 26 at 16:21










  • @JeffSchaller Great question, that is specified within the python code, specifically with a call to start an app server with the flask library/framework.
    – Unknown Coder
    Jun 26 at 16:25










  • So the parameter mywebapp.py is enough to determine the port?
    – Jeff Schaller
    Jun 26 at 16:31
















  • where does the port number get specified when you start(ed) them?
    – Jeff Schaller
    Jun 26 at 16:21










  • @JeffSchaller Great question, that is specified within the python code, specifically with a call to start an app server with the flask library/framework.
    – Unknown Coder
    Jun 26 at 16:25










  • So the parameter mywebapp.py is enough to determine the port?
    – Jeff Schaller
    Jun 26 at 16:31















where does the port number get specified when you start(ed) them?
– Jeff Schaller
Jun 26 at 16:21




where does the port number get specified when you start(ed) them?
– Jeff Schaller
Jun 26 at 16:21












@JeffSchaller Great question, that is specified within the python code, specifically with a call to start an app server with the flask library/framework.
– Unknown Coder
Jun 26 at 16:25




@JeffSchaller Great question, that is specified within the python code, specifically with a call to start an app server with the flask library/framework.
– Unknown Coder
Jun 26 at 16:25












So the parameter mywebapp.py is enough to determine the port?
– Jeff Schaller
Jun 26 at 16:31




So the parameter mywebapp.py is enough to determine the port?
– Jeff Schaller
Jun 26 at 16:31










2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










You can use lsof to find the process id associated with a known port number



lsof -i :*port*



Alternatively, you may wish to use netstat which can display all network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.



Try netstat -tulpn






share|improve this answer























  • This sounds like its along the right track but this server does not have lsof and I cant use apt-get. Are there any other commands similar to this that you would recommend?
    – Unknown Coder
    Jun 26 at 16:31






  • 1




    if you have netstat you may be able to find it using netstat -tulpn. You may have to grep the output for it to be useful.
    – Tyler Chambers
    Jun 26 at 16:35






  • 1




    That did it, thank you! I can see the ports and then it gives me the PID in the last column, this is perfect!
    – Unknown Coder
    Jun 26 at 16:37

















up vote
1
down vote













One other way is to add it to the flask app itself.



from os import getpid
print("Creating PID file.")
fh=open("/var/run/yourAppNameWithPort.pid", "w")
fh.write(str(getpid()))
fh.close()





share|improve this answer





















  • Is this something I would do before I startup the app or can I do it even while the app is running?
    – Unknown Coder
    Jun 26 at 16:34










  • You'd add this to you app, it would happen on startup. I usually use argparse and pass in the pidfile name as an argument, but that is just my preference.
    – Joe M
    Jun 27 at 2:06










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f452048%2fget-python-process-id-for-a-flask-web-site-and-or-port-number%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










You can use lsof to find the process id associated with a known port number



lsof -i :*port*



Alternatively, you may wish to use netstat which can display all network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.



Try netstat -tulpn






share|improve this answer























  • This sounds like its along the right track but this server does not have lsof and I cant use apt-get. Are there any other commands similar to this that you would recommend?
    – Unknown Coder
    Jun 26 at 16:31






  • 1




    if you have netstat you may be able to find it using netstat -tulpn. You may have to grep the output for it to be useful.
    – Tyler Chambers
    Jun 26 at 16:35






  • 1




    That did it, thank you! I can see the ports and then it gives me the PID in the last column, this is perfect!
    – Unknown Coder
    Jun 26 at 16:37














up vote
1
down vote



accepted










You can use lsof to find the process id associated with a known port number



lsof -i :*port*



Alternatively, you may wish to use netstat which can display all network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.



Try netstat -tulpn






share|improve this answer























  • This sounds like its along the right track but this server does not have lsof and I cant use apt-get. Are there any other commands similar to this that you would recommend?
    – Unknown Coder
    Jun 26 at 16:31






  • 1




    if you have netstat you may be able to find it using netstat -tulpn. You may have to grep the output for it to be useful.
    – Tyler Chambers
    Jun 26 at 16:35






  • 1




    That did it, thank you! I can see the ports and then it gives me the PID in the last column, this is perfect!
    – Unknown Coder
    Jun 26 at 16:37












up vote
1
down vote



accepted







up vote
1
down vote



accepted






You can use lsof to find the process id associated with a known port number



lsof -i :*port*



Alternatively, you may wish to use netstat which can display all network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.



Try netstat -tulpn






share|improve this answer















You can use lsof to find the process id associated with a known port number



lsof -i :*port*



Alternatively, you may wish to use netstat which can display all network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.



Try netstat -tulpn







share|improve this answer















share|improve this answer



share|improve this answer








edited Jun 26 at 16:40


























answered Jun 26 at 16:26









Tyler Chambers

3016




3016











  • This sounds like its along the right track but this server does not have lsof and I cant use apt-get. Are there any other commands similar to this that you would recommend?
    – Unknown Coder
    Jun 26 at 16:31






  • 1




    if you have netstat you may be able to find it using netstat -tulpn. You may have to grep the output for it to be useful.
    – Tyler Chambers
    Jun 26 at 16:35






  • 1




    That did it, thank you! I can see the ports and then it gives me the PID in the last column, this is perfect!
    – Unknown Coder
    Jun 26 at 16:37
















  • This sounds like its along the right track but this server does not have lsof and I cant use apt-get. Are there any other commands similar to this that you would recommend?
    – Unknown Coder
    Jun 26 at 16:31






  • 1




    if you have netstat you may be able to find it using netstat -tulpn. You may have to grep the output for it to be useful.
    – Tyler Chambers
    Jun 26 at 16:35






  • 1




    That did it, thank you! I can see the ports and then it gives me the PID in the last column, this is perfect!
    – Unknown Coder
    Jun 26 at 16:37















This sounds like its along the right track but this server does not have lsof and I cant use apt-get. Are there any other commands similar to this that you would recommend?
– Unknown Coder
Jun 26 at 16:31




This sounds like its along the right track but this server does not have lsof and I cant use apt-get. Are there any other commands similar to this that you would recommend?
– Unknown Coder
Jun 26 at 16:31




1




1




if you have netstat you may be able to find it using netstat -tulpn. You may have to grep the output for it to be useful.
– Tyler Chambers
Jun 26 at 16:35




if you have netstat you may be able to find it using netstat -tulpn. You may have to grep the output for it to be useful.
– Tyler Chambers
Jun 26 at 16:35




1




1




That did it, thank you! I can see the ports and then it gives me the PID in the last column, this is perfect!
– Unknown Coder
Jun 26 at 16:37




That did it, thank you! I can see the ports and then it gives me the PID in the last column, this is perfect!
– Unknown Coder
Jun 26 at 16:37












up vote
1
down vote













One other way is to add it to the flask app itself.



from os import getpid
print("Creating PID file.")
fh=open("/var/run/yourAppNameWithPort.pid", "w")
fh.write(str(getpid()))
fh.close()





share|improve this answer





















  • Is this something I would do before I startup the app or can I do it even while the app is running?
    – Unknown Coder
    Jun 26 at 16:34










  • You'd add this to you app, it would happen on startup. I usually use argparse and pass in the pidfile name as an argument, but that is just my preference.
    – Joe M
    Jun 27 at 2:06














up vote
1
down vote













One other way is to add it to the flask app itself.



from os import getpid
print("Creating PID file.")
fh=open("/var/run/yourAppNameWithPort.pid", "w")
fh.write(str(getpid()))
fh.close()





share|improve this answer





















  • Is this something I would do before I startup the app or can I do it even while the app is running?
    – Unknown Coder
    Jun 26 at 16:34










  • You'd add this to you app, it would happen on startup. I usually use argparse and pass in the pidfile name as an argument, but that is just my preference.
    – Joe M
    Jun 27 at 2:06












up vote
1
down vote










up vote
1
down vote









One other way is to add it to the flask app itself.



from os import getpid
print("Creating PID file.")
fh=open("/var/run/yourAppNameWithPort.pid", "w")
fh.write(str(getpid()))
fh.close()





share|improve this answer













One other way is to add it to the flask app itself.



from os import getpid
print("Creating PID file.")
fh=open("/var/run/yourAppNameWithPort.pid", "w")
fh.write(str(getpid()))
fh.close()






share|improve this answer













share|improve this answer



share|improve this answer











answered Jun 26 at 16:27









Joe M

5964




5964











  • Is this something I would do before I startup the app or can I do it even while the app is running?
    – Unknown Coder
    Jun 26 at 16:34










  • You'd add this to you app, it would happen on startup. I usually use argparse and pass in the pidfile name as an argument, but that is just my preference.
    – Joe M
    Jun 27 at 2:06
















  • Is this something I would do before I startup the app or can I do it even while the app is running?
    – Unknown Coder
    Jun 26 at 16:34










  • You'd add this to you app, it would happen on startup. I usually use argparse and pass in the pidfile name as an argument, but that is just my preference.
    – Joe M
    Jun 27 at 2:06















Is this something I would do before I startup the app or can I do it even while the app is running?
– Unknown Coder
Jun 26 at 16:34




Is this something I would do before I startup the app or can I do it even while the app is running?
– Unknown Coder
Jun 26 at 16:34












You'd add this to you app, it would happen on startup. I usually use argparse and pass in the pidfile name as an argument, but that is just my preference.
– Joe M
Jun 27 at 2:06




You'd add this to you app, it would happen on startup. I usually use argparse and pass in the pidfile name as an argument, but that is just my preference.
– Joe M
Jun 27 at 2:06












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f452048%2fget-python-process-id-for-a-flask-web-site-and-or-port-number%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

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

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay