Getting the running process’ own pid in Python

Posted on

How to get the running process’ pid in Python? In Python, you can get the pid of the current process by import os os.getpid() From the official doc: os.getpid() Return the current process id. One example os using os.getpid() to get process own ID: $ python3 Python 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0]
Read more

How to find the disk where root / is on in Bash on Linux?

Posted on

Question: how to find the disk where the Linux’s root(/) is on in Bash? The root may be on a LVM volume or on a raw disk. 2 cases: One example: # df -hT | grep /$ /dev/sda4 ext4 48G 32G 14G 71% / For another example: # df -hT | grep /$ /dev/mapper/fedora-root ext4
Read more

How to set Zimbra web service’s hostname and port?

Posted on

In Zimbra server, how to set Zimbra web service’s hostname and port? Set Zimbra Web service’s host and port (to mail.domain.com:80 as an example) for a mail domain domain.com: zmprov md domain.com zimbraPublicServiceHostname mail.domain.com zmprov md domain.com zimbraPublicServicePort 80 Reference: https://wiki.zimbra.com/wiki/When_using_a_proxy,_the_’change_password’_box_doesn’t_load

Getting Hostname in C Programs in Linux

Posted on

In C, how to get the hostname of the node? In C, you may use the gethostname function. #include <unistd.h> int gethostname(char *name, size_t namelen); The gethostname() function shall return the standard host name for the current machine. The namelen argument shall specify the size of the array pointed to by the name argument. The
Read more

How to get the hostname of the node in C++?

Posted on

In C++, how to get the hostname of the node? In C++, the C way works too. However, with Boost, you can use the boost::asio::ip::host_name() function to get the hostname as a std::string: namespace boost { namespace asio { namespace ip { /// Get the current host name. BOOST_ASIO_DECL std::string host_name(); … More at http://www.boost.org/doc/libs/1_63_0/boost/asio/ip/host_name.hpp
Read more

Getting Hostname in Bash in Linux in 3 Ways

Posted on

Getting the hostname of the node running a program can be useful in various scenarios, such as creating logs with the hostname, identifying which node a script is running on, or configuring a distributed system with different nodes. In Bash, there are several ways to retrieve the hostname of the machine, as mentioned in the
Read more

How to get the hostname of the node in Python?

Posted on

In Python, how to get the hostname of the node? In Python, you can get the hostname by the socket.gethostname() library function in the socket module: import socket hostname = socket.gethostname() Example: $ python Python 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2 Type “help”, “copyright”, “credits” or “license”
Read more

How to get hostname in Python on Linux?

Posted on

In Python, how to get hostname as the command hostname does on Linux? In Python, you can get the hostname by the socket.gethostname() library function in the socket module: import socket hostname = socket.gethostname() Reference: https://www.systutorials.com/dtivl/20/how-to-get-the-hostname-of-the-node?show=34#a34

How to put files with spaces in names into HDFS?

Posted on

I got this error when I tried to save a file with a space in its name into HDFS: $ hdfs dfs -put -f “/home/u1/testa/test a” “/u1/testa/test a” put: unexpected URISyntaxException while the HDFS seems allow spaces in its file names: https://hadoop.apache.org/docs/r2.7.3/hadoop-project-dist/hadoop-common/filesystem/model.html . How to achieve the effect of saving the files with spaces in
Read more

How to get an environment variable in Python?

Posted on

In Python, how to get an environment variable? In Python, you may use this piece of code to get an environment variable: os.environ.get(‘ENV_MIGHT_EXIST’) or this piece of code: os.getenv(‘ENV_MIGHT_EXIST’) It will return None if the environment variable is not present. Reference and for more ways, please check https://www.systutorials.com/dtivl/13/how-to-get-an-environment-variable?show=80#answer-80 .

How to set process with lowest priority?

Posted on

In system, sometimes, we need backstage threads with very very low priority since it cannot preempt any normal process asks for CPU. SCHED_IDLE class satisfies this requirement which has the priority lower than “nice=19” of CFS. Following code does this. 241 void set_idle_priority(void) { 242 struct sched_param param; 243 param.sched_priority = 0; 244 int s
Read more