How to set one task’s CPU affinity quickly? 1, Get this task’s ID # taskset -pc PID 2, Set this task’s CPU affinity # taskset -c affinity ./task There is also another format # taskset -pc affinity pid For example: set process with PID 3783 to CPU 15 # taskset -pc 15 3783
Tag: Tutorial
How to install gfortran on CentOS 7?
Posted onHow to install the gfortran fortran compiler on CentOS 7 Linux? gfortran on CentOS 7 is provided in the gcc-gfortran package. You may install it to install gfortran. # yum install gcc-gfortran Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: ftp.cuhk.edu.hk * epel: ftp.cuhk.edu.hk * extras: centos.01link.hk * nux-dextop: li.nux.ro *
Read more
How to configure SPF for my email domain hosted by DreamHost?
Posted onMy domain’s email is hosted by DreamHost and all my emails from that domain are sent using DreamHost’s SMTP. How to configure the SPF record for my email domain hosted by DreamHost? For a domain with email and SMTP hosted by DreamHost, you can set its SPF record to v=spf1 include:netblocks.dreamhost.com Reference: What SPF records
Read more
How to get vCPU thread ID in QEMU/KVM host OS?
Posted onIn order to collect more information about CPU information internal guest OS, we usually need to get vCPU’s thread ID in host OS. Solution 1: Under directory ‘/sys/fs/cgroup/cpuset/machine’, you will find virtual_machine_name.libvirt-qemu directory. And under this directory, you will find all vCPU sub-directories and under these dirs, you will find vCPU thread IDs. For example
Read more
How to limit a user’s CPU resources in Linux Systems
Posted onWhen you use a server with other users, you might want to limit other users’ CPU resources for some specific aims. Cgroup has lots of parameters we can use to control computer resources. For CPU resources, you can tune cpu.shares parameter to limit users’ CPU resources. To be more precise, change directory to /sys/fs/cgroup/cpu/user and
Read more
How to disable the fastestmirror yum plugin in CentOS 7 Linux?
Posted onHow to disable the fastmirror yum plugin in CentOS 7 Linux? The fastestmirror function of yum is provided by the package `yum-plugin-fastestmirror`. However, because `yum` depends on it, the `yum-plugin-fastestmirror` package can not be removed. If you try to remove it, `yum` will report failures like. # yum remove yum-plugin-fastestmirror Loaded plugins: fastestmirror Resolving Dependencies
Read more
How to get processes’ I/O utilization percentage
Posted onTwo notices: 1, a process has only one main thread which is itself. 2, a process has many threads. Solution 1: Please use taskstats [1] related interfaces, and send TASKSTATS_TYPE_PID and TASKSTATS_TYPE_TGID commands to kernel to get a process’s ‘blkio_delay_total’ parameter for a process with one main thread and a process with threads separately. Solution
Read more
For QEMU/KVM, how to share data between host and guest
Posted onGeneral question for developers to access data between VM and VMM. As I know, paravirtualization solution is a good way to share data for VM and VMM since it has better performance. Please use Virtio 9p solution for QEMU/KVM. Note that you need to load 9p related modules for guest kernel. Add following in your
Read more
Cannot make directory ‘/var/run/screen/S-apache’: Permission denied
Posted onHello! Im trying to create a screen folder for the user apache, Not root. But it seems to fail, I have no idea on how to fix this issue. I only get the error: Cannot make directory ‘/var/run/screen/S-apache’: Permission denied Im using Cent OS 7 There may be various possible reasons. 2 common reasons: screen
Read more
How to add PHP DOMDocument extension to httpd in CentOS 7?
Posted onJust migrated a PHP site to a new server. However, in /var/log/httpd/error_log, there are errors like [:error] [pid 2810] [client 61.92.242.24:43372] PHP Fatal error: Class ‘DOMDocument’ not found in /var/www/…/some.php on line 16 How to add PHP DOMDocument extension to httpd in CentOS 7? You need to install the package php-xml to have DOMCoument support
Read more
How to make iptables/ip6tables configurations permanent across reboot on CentOS 7 Linux?
Posted onHow to make iptables/ip6tables configurations permanent across reboot on CentOS 7 Linux? CentOS 7 uses FirewallD by default. If you would like to manage iptables/ip6tables rules directly without using FirewallD, you may use the old good iptables-services service which will load the iptables/ip6tables rules saved in /etc/sysconfig/iptables and /etc/sysconfig/ip6tables when it is started during boot
Read more
How to convert a piece of HTML code to plain text in PHP?
Posted onHow to convert a piece of HTML code to plain text without leading and ending spaces in PHP? For example, I would like to convert <div> <b>hello</b> world</div> to a string hello world You may use this piece of code in PHP to strip HTML tags, remove leading and ending spaces and convert special characters
Read more
How to get a substring at words boundaries in PHP?
Posted onHow to get a substring at words boundaries in PHP? For example, for a string $a = “ab cc dde ffg ff”;, I would like to get its substring of length at most 7 from position 0 without breaking words. A simple substring($a, 0, 7) will break the word dde. Here, we consider “words” are
Read more
How to get the full request URL in PHP?
Posted onHow to get the full request URL of the page being processed in PHP? If you are sure the request is a http or https one, and the PHP script is executed according to (e.g. by a load balancer or apache reverse proxy) the REQUEST_URI/HTTP_HOST which are set by the client, the PHP script can
Read more
How to pause and resume the execution of a process on Linux?
Posted onHow to pause the execution of a process on Linux so that the CPU can be freed? Later, if the node is idle again, how to resume the execution? There are 2 signals related to stopping (pausing) and continuing (resuming) processes: Stop Default action is to stop the process. Cont Default action is to continue
Read more
How to upgrade vim to version 8 on CentOS 7?
Posted onvim on CentOS 7 is version 7.4 with patches 1-160: $ vim –version VIM – Vi IMproved 7.4 (2013 Aug 10, compiled Dec 21 2016 17:00:20) Included patches: 1-160 How to upgrade it to version 8 which is the latest major version? Update on Oct 23 2018: the repository introduced in the original method is
Read more
How to print all fields after a certain field with awk on Linux?
Posted onHow to print all fields after a certain field with awk on Linux? Say, I want to print out all fields after field $3: a b c d e f a b b b a a c d should be transformed to d e f b d You may use a for loop in awk
Read more
How to disable PHP short open tags?
Posted onSome of my pages has XML tags like ‘<?xml ?>’ which are considered by PHP as short open tags ‘<? ?>’. How to disable PHP short open tags? In PHP, to disable the short open tags, you can set the variable short_open_tags = FALSE; in your php.ini. Reference: short_open_tags in php.ini
How to find out all files with replication factor 1 in HDFS?
Posted onHow to find out all files with replication factor 1 in HDFS? The hdfs dfsadmin -report shows there are blocks with replication factor 1: Missing blocks (with replication factor 1): 7 How to find them out? You can run hdfs fsck to list all files with their replication counts and grep those with replication factor
Read more
How to add a prefix string at the beginning of each line in Bash shell script on Linux?
Posted onHow to add a prefix string at the beginning of each line in Bash shell script on Linux? For example, assume we have a file a.txt: line 1 line 2 I want to have, pre line 1 pre line 2 You may use sed, the stream editor for filtering and transforming text: sed -e ‘s/^/pre
Read more