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 .
Category: QA
Questions and answers.
How to get an environment variable in Go?
Posted onIn Go lang, how to get an environment variable? To get an environment variable (e.g. “VAR”) in GO: import “os” import “fmt” fmt.Println(“VAR:”, os.Getenv(“VAR”))
How to convert a byte[] to io.Reader in Go?
Posted onHow to convert a byte[] to io.Reader in Go directly? You can use the NewReader() func from the bytes package of Go to convert bytes to io.Reader. For example, reader := bytes.NewReader(thebytes)
how to get the size of python file without using the os namespace
Posted oni need to create a program which is taking information from printer , so that i cannot use os namespace , so there is any way without using the os namespace You may use a way as follows. open the file seek to the end tell its position which is the file size An example
Read more
How to effectively disable a Linux user account?
Posted onNot yet to totally delete the Linux user account, but how to effectively disable a Linux user account? That is, disable a user account while keep all its files/configurations. Later, if it is needed, so that I can enable it again. To effectively disable a Linux user account so that it can’t login using its
Read more
How to set process with lowest priority?
Posted onIn 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
How to do a good research in system field?
Posted onWe may need to check some materials about how to do good research in system field if you a Ph.D. focusing on system research. Some references: 1, How to write a good systems paper 2, How to be a good graduate student 3, Doing a System Ph.D. 4, Giving an Academic Talk Welcome to add
Read more
How to read the whole file content into a string in Go?
Posted onHow to read the whole file content into a string in Go? You can use the ReadFile() func from the io/ioutil package in Go to read the whole file content: func ReadFile(filename string) ([]byte, error) For example, read file filepath content and check the error: if bytes, err := ioutil.ReadFile(filepath); err != nil { log.Fatal(“Failed
Read more
What is the vruntime of one process after it is moved into another run queue in Linux Kernel
Posted onWhen we do migration, one process will be migrated from one source CPU’s runqueue to destination CPU’s run queue. What is the virtual run time (if CFS is used) after it is moved into destination CPU’s run queue? When the process is dequeued from source CPU’s run queue, its vruntime will minus the minimum vruntime
Read more
How to use ioprio_set in linux c
Posted onSince there is no glibc wrapper for ioprio_set in linux c, we need to call this API with some definition. Using syscall in linux as follows. syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, pid, IOPRIO_PRIO_CLASS(IOPRIO_CLASS_IDLE)); Some other definitions to declare above macros. 69 enum { 70 IOPRIO_CLASS_NONE, 71 IOPRIO_CLASS_RT, 72 IOPRIO_CLASS_BE, 73 IOPRIO_CLASS_IDLE, 74 }; 75 76 enum { 77
Read more
Libvirt crash when upgrade from version 1.2.2 to version 2.5.0
Posted onIf you install libvirt from ubuntu software library like this sudo apt-get install libvirt-bin The default version is 1.2.2 for Ubuntu Trusty. However, after you upgrade it to version 2.5.0 from its source codes (restart the libvirtd service), you will see following error if you want to install vm with virt-install. # ./installkvm1.sh Starting install…
Read more
How to install encfs on CentOS 6?
Posted onI noticed your answer on configuring encfs on CentOS 6. I had difficulties installing encfs on CentOS 6. How did you install it? Thanks. For CentOS 6, I used a slightly old version (version 1.7.4) using an RPM built for by PUIAS: For x86-64 version: # yum install http://puias.princeton.edu/data/puias/6/x86_64/os/Addons/fuse-encfs-1.7.4-1.puias6.x86_64.rpm For i686 version: # yum install
Read more
Where to download an old release package of Hadoop?
Posted onThe download page of Hadoop http://hadoop.apache.org/releases.html only contains several recent release packages. I would like to download some old release packages such as Hadoop 2.5.0 which is not available anymore on the release page. Where to download a copy of the old release? You can download the old release packages of Hadoop on the http://archive.apache.org
Read more
Cannot start VM with error “no network with matching name ‘default'”
Posted onI update libvirt version and want to start VM with the new libvirt tools but I failed as follows. > sudo virsh start kvm1 error: Failed to start domain kvm1 error: Network not found: no network with matching name ‘default’ It seems that the default ‘virbr0’ is missing after I update libvirt so I solve
Read more
How to install Tex Live on CentOS 7 Linux?
Posted onThe LaTex packages in CentOS 7 Linux is not sufficient enough. I would like to Install Tex Live such as Tex Live 2016. How could I install it on CentOS 7? The best way I found is to use the texlive offical installation tool to install the full packages for texlive 2016. It will take
Read more
Extract Images from a PDF File in Linux
Posted onHow to extract the images from a PDF file in Linux? You may use the pdfimages tool. To output jpg images from a PDF ./a.pdf, run pdfimages -j ./a.pdf ./images ./images is the output images’ prefix. The images in ./a.pdf will be extracted and saved as ./images-nnn.jpg. -j options make pdfimages generate JPEG files.
How to output function stack in Linux Kernel
Posted onIn Linux Kernel, we usually trace/debug what kind of events will trigger the phenomena we find in the system. For example, what kind of event will trigger the fact that the timeslice of one process will be very short. In order to solve these kind of problems, we need to output the function stack. Currently,
Read more
encfs on CentOS 6 can’t mount as normal user
Posted onOn CentOS 7, using a normal user, encfs works just well. On CentOS 6, using the root user, encfs works. However, the problem is, on CentOS 6, using a normal user account, encfs does not work as on CentOS 7. $ encfs -s ~/t/.enc ~/t/enc EncFS Password: fuse: failed to exec fusermount: Permission denied fuse
Read more
What’s the difference between memory coherence and consistency?
Posted onIn memory hierarchical, it needs to be coherence and consistency. However, they are different things. What are the differences? Memory coherence: a memory system is coherent if any read of a data item returns the most recently written value of that data item (what values can be returned by a read). Memory consistency: A memory
Read more
How to install dia on CentOS 7 Linux?
Posted onDia seems not available in the official repository of CentOS 7. How to install dia on CentOS 7 Linux? You can find built dia packages in some additional repositories for CentOS. First, enable EPEL following this link. Second, enable Nux Desktop following this link. Then, you can install dia by # yum install dia