Update heap size for Tomcat8 in Linux

If you install Tomcat8 (even tomcat7) via apt you will need to edit the file /etc/default/tomcat8   (or tomcat7) and look for the JAVA_OPTS variable. The Xmx value is there and you can set it as required.

Ubuntu 16.04.1 slows down while idle – kidle processes

Warning: the below might make your CPU run hotter or overheat – use at your own risk!

A new Ubuntu 16.04.1 installation – after short usage the computer slows down and the CPUs are about 50% busy. There are some kidle_inject processes running which take this valuable CPU.

Top shows the following:

 6898 root -51 0 0 0 0 S 47.1 0.0 1:20.16 kidle_inject/5 
 6900 root -51 0 0 0 0 S 47.1 0.0 1:20.38 kidle_inject/7 
 6894 root -51 0 0 0 0 S 41.2 0.0 1:13.55 kidle_inject/1 
 6895 root -51 0 0 0 0 S 41.2 0.0 1:16.90 kidle_inject/2 
 6896 root -51 0 0 0 0 S 41.2 0.0 1:18.28 kidle_inject/3 
 6897 root -51 0 0 0 0 S 41.2 0.0 1:18.64 kidle_inject/4 
 6899 root -51 0 0 0 0 S 41.2 0.0 1:20.02 kidle_inject/6 
 6893 root -51 0 0 0 0 S 29.4 0.0 1:08.23 kidle_inject/0

To stop these processes run the following command – it will disable them only for the current session. I very rarely reboot so I haven’t looked into making it permanent yet.

$ sudo rmmod intel_powerclamp


Add an alias on a network interface in Linux

$ sudo ip link set dev enp0s25 alias test
$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s25: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
    link/ether 68:f7:28:84:38:ce brd ff:ff:ff:ff:ff:ff
    alias test
3: wlp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000
    link/ether 60:57:18:cf:0c:6a brd ff:ff:ff:ff:ff:ff

Enable export of all environment variables in bash

When setting up environment variables, for example in .profile you can write the following near the top of the file to enable exporting of all the environment variables without explicitly writing “export” each time:

set -o allexport

with the above, then you can just write the following, for example:


instead of

export TEST_DIR=/tmp/test

To disable the all export:

set +o allexport

You are also able to set environment variables without the export or allexport, however that will NOT make the variable available to sub-processes.

Count bytes and characters with wc

Count bytes and characters with wc

wc -c filename == counts the bytes
wc -m filename == counts the characters

this can be combined with other commands like grep, awk, sed

example with sed:

sed -n '1p' filename | wc -c

the above will print the first line from filename and count the bytes in that line

Fix ^M in Linux/UNIX using vi/vim

Sometimes if you edit a file in windows and then open it in Linux/UNIX it will have the special characters ^M at the end of each sentence. To fix ^M in Linux/UNIX using vi/vim run the following:

%s/[ctrlkey+v and ctrl-key+M]//g

sed tricks to replace multi blank spaces and tabs with single space

Replace all multi-blankspaces (more than one spaces/tabs) in file with mono-blankspace (one space):

sed 's/[<space>][<tab>][<space>][<tab>]*/ /g' filename

can also be:

 sed 's/[<space>][<tab>][<space>][<tab>]*/ /g' filename > newfilename

note: g in the end means GLOBAL

In the above samples, <space> means ‘ ‘ (empty space) and <tab> means ‘      ‘ (tab key press).

Finding and cleaning Oracle locks

How to find blocking sessions in Oracle (11g). This is used to make sure that the object which we are trying to update is actually locked by another session:

 v$locked_object a ,
 v$session b,
 dba_objects c
 b.sid = a.session_id
 a.object_id = c.object_id;

And this query tells which are the problem sessions:

select l1.sid, ' IS BLOCKING ', l2.sid
from v$lock l1, v$lock l2
where l1.block =1 and l2.request > 0
and l1.id1=l2.id1
and l1.id2=l2.id2;

So now we have the SID of the problem session and we only need the serial number to kill it.

SELECT serial# FROM v$session WHERE sid=<sid>

And now kill it:

ALTER SYSTEM KILL SESSION '<sid>,<session#>'

Check tablespace free space and total used – Oracle

Use the below SQL query to check the total, used and free space in all the tablespaces in the database

   fs.tablespace_name                          "Tablespace", 
   (df.totalspace - fs.freespace)              "Used MB", 
   fs.freespace                                "Free MB", 
   df.totalspace                               "Total MB", 
   round(100 * (fs.freespace / df.totalspace)) "Pct. Free" 
      round(sum(bytes) / 1048576) TotalSpace 
   group by 
   ) df, 
      round(sum(bytes) / 1048576) FreeSpace 
   group by 
   ) fs 
   df.tablespace_name = fs.tablespace_name;

If you are running this in sqlplus you might want to format the columns first

column "Tablespace" format a13
column "Used MB" format 99,999,999
column "Free MB" format 99,999,999
column "Total MB" format 99,999,999


Go to Top