Get python process ID for a flask web site and/or port number?
Clash 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?
rhel python kill nohup
add a comment |Â
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?
rhel python kill nohup
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 parametermywebapp.py
is enough to determine the port?
â Jeff Schaller
Jun 26 at 16:31
add a comment |Â
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?
rhel python kill nohup
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?
rhel python kill nohup
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 parametermywebapp.py
is enough to determine the port?
â Jeff Schaller
Jun 26 at 16:31
add a comment |Â
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 parametermywebapp.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
add a comment |Â
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
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 havenetstat
you may be able to find it usingnetstat -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
add a comment |Â
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()
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
add a comment |Â
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
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 havenetstat
you may be able to find it usingnetstat -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
add a comment |Â
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
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 havenetstat
you may be able to find it usingnetstat -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
add a comment |Â
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
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
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 havenetstat
you may be able to find it usingnetstat -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
add a comment |Â
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 havenetstat
you may be able to find it usingnetstat -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
add a comment |Â
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()
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
add a comment |Â
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()
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
add a comment |Â
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()
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()
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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