Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I discover if a program is running from command line or from web?

I have a python script and I wanna know if the request is from web or from command line. How can I do this?

like image 540
Frias Avatar asked Oct 29 '10 01:10

Frias


People also ask

How do I find out what programs are running on my server?

Open the terminal window on Linux. For remote Linux server use the ssh command for log in purpose. Type the ps aux to see all running process in Linux. Alternatively, you can issue the top command or htop command to view running process in Linux.


1 Answers

When run as a CGI, environment variables such as REQUEST_METHOD will be present. If not, then you're not running in a CGI environment.

You can check this like this:

import os
if os.getenv("REQUEST_METHOD"):
    print("running as CGI")
else:
    print("not running as CGI")
like image 74
Greg Hewgill Avatar answered Oct 23 '22 16:10

Greg Hewgill