Kristian Lunde

Archive for the ‘Linux’ Category

CentOS, where is all my memory gone?

with 3 comments

I encountered a rather strange issue on one of MySapients CentOS 5 servers the other day, the server seemed to run fine, without any issues what so ever, but it seem to run very low on memory. In fact it only had 150MB memory available of a total 4GB.

This obviously caused me a bit of a worry, but after some digging around I found the answer, linux is borrowing unused memory to do disk caching. Memory is automatically reassigned when the server needs to allocate memory to other services, in other words there is nothing to worry about.

There is a good site about this describing this functionality in more detail, you can read it at:

Written by Kristian Lunde

January 15th, 2010 at 10:25 pm

Posted in Linux

My 7 things

with 2 comments

The 7 things have been all around the PHP community for a while now, and I got tagged by Christer a while ago. So I guess I should go around and publish my seven things:

  1. I am an assisting nurse graduate
  2. I have a 3 year old daughter
  3. Expired dairy products are some of the most disgusting things I know
  4. I dream of some day having a small cabin by the lake, without any internet or television?!?
  5. I often think about how it would be like to be the only person alive on the earth. (Something similar to the “I am legend” movie, without the zombies).
  6. I took dance lessons when I was a kid, however I really suck at dancing.
  7. I drink way to much Pepsi

Those seven things were not really interesting at all, but it was all I could get together for now. Who knows someday I just might publish: “the top 1000 things you did not know about me” :P

My lucky seven bloggers which I tag are:

Here are some rules that must be followed by anyone who decide to follow up:

* Link your original tagger(s), and list these rules on your blog.
* Share seven facts about yourself in the post – some random, some wierd.
* Tag seven people at the end of your post by leaving their names and the links to their blogs.
* Let them know they’ve been tagged by leaving a comment on their blogs and/or Twitter.

Written by Kristian Lunde

January 22nd, 2009 at 1:34 am

Posted in Linux,Misc

2.5 applications I really miss in OS X

with 3 comments

In a previous post I wrote about my new life running on a MacBook Pro and OSX. It has now been over a month since I switch over to this unix hybrid, and I am quite liking it. It is very stable, I almost never turn off my mac, but I put it to sleep, this is working fine and my last reboot is over two weeks ago. I have also gotten used to some of the new weird keys on the keyboard and the shortcuts, but I am not yet as efficent on a mac as I am/were on ubuntu/windows. During the last few weeks I have discovered that Apple and other in most cases provide me with the applications I need, but not always, and here is the list of applications I really miss:

1. TortoiseSVN
Windows application which integrates itself with Windows Explorer and provide a SVN client. I would say that this is the best graphical SVN client I have ever used. SVNX which I currently use on the mac is not a very good replacement.

2. Kate / Notepad++
Kate is a KDE text editor for unix based systems. Notpad++ is Kates equivalent on Windows. Both editors provide a simple and intuitive user interface, and a lot of syntax highlight files for all the obscure programming languages you can think of.
I know Mac have the TextMate application, but that is third party software and you have to pay €48 or something for a license, and that is probably what I probably will do. The TextMate application is really good and provide most if not all the functionality that Kate and Notepad++ provide.

In my desperation for a good text editor I almost went off and tried to install KDE on Mac, but that was said to be experimental and could break my entire system. So that is a no go for now. The article however was really interesting:


I still miss my ubuntu system and will probably go off and install parallels or vmware and ubuntu, just to have it accessible :)

Written by Kristian Lunde

December 3rd, 2008 at 11:51 pm

Posted in Mac,Ubuntu

Tagged with , , , ,

Firefox killing the sound on my Ubuntu box

without comments

Tonight I encountered a rather strange problem on my Ubuntu box. While doing nothing special on my machine, just surfing and listening to music and suddenly there are no sound?!?

Doing a quick search on I quickly found the solution. The problem seems to be Firefox, killing the firefox sessions and restarting the alsa-utils did the trick for me, and voila the sound is back :D

The howto get the sound back is found here:

BTW: starting firefox again did not cause any problems ;)

Written by Kristian Lunde

June 27th, 2008 at 9:25 pm

Posted in Linux,Ubuntu

Tagged with , ,

Using GNU screen

without comments

Recently I’ve been the victim of a really unstable internet connection. This lack of stability has made me a great fan of the GNU screen command in unix systems.

GNU Screen is a small piece of software that lets you initiate a number of terminals inside a single terminal window. The great advantage with screen is that if you loose your internet connection, the screen terminals and operations inside these terminals still run on the server, contrary to operations running directly on the terminal window of your external server.

Screen is real simple and in most cases you only need a few important commands:

  • starting a session
  • listing all running sessions
  • attaching to a session
  • de attaching from a session
  • killing a session

Creating a new screen session

Command: screen

kristian@Saturn:~$ screen 


Listing all active screen sessions

Command: screen -ls


kristian@Saturn:~$ screen -ls
  1. There are screens on:
  2.  11179.pts-0.Saturn (Detached)
  3.  11114.pts-0.Saturn (Detached)
  4. 2 Sockets in /var/run/screen/S-kristian.

Attaching to a session

If only one screen session is active the command below will take you directly to the session. If there are several sessions running the command below will display a list of running sessions. To choose one of them the screen -r command has to be followed by the session name.

Command: screen -r

Example of several screen sessions running:

kristian@Saturn:~$ screen -r
  1. There are several suitable screens on:
  2.  11179.pts-0.Saturn (Detached)
  3.  11114.pts-0.Saturn (Detached)
  4. Type "screen [-d] -r [pid.]" to resume one of them.

Example of attaching to a screen session:

kristian@Saturn:~$ screen -r 11179.pts-0.Saturn

De attaching from a session

De attaching from a screen session is real simple just remember the key combinations :P

Hold the CTRL key down, press A, then D. Thats it.

Killing a screen session

Killing a session is as simple as de attaching from one, just use the correct key combinations.

Keep the CTRL button down, press A, then K.

Written by Kristian Lunde

May 27th, 2008 at 10:14 pm

Posted in Linux

Tagged with ,

My first introduction to java and databases

with 2 comments

The other day I did a complete reconfiguration of java on my system. Tonight I started to play around with java and postgresql. I installed PostgreSQL 8.2 (yes I know 8.3 is out there), and downloaded the jdbc driver for PosgreSQL.


After installing PostgreSQL, you have to add a user to the authorization file pg_hba.conf located in /etc/postgresql/8.x/main on a ubuntu system, remember to restart the postgreSQL server after editing pg_hba.conf. When that is done add the same user to the postgreSQL server either by using postgreSQL’s createuser function or by logging into the postgreSQL server and doing a SQL CREATE USER, I did the latter one.

  1. CREATE USER kristian WITH PASSWORD 'xxxxxxxx' CREATEDB;

This enables me to do a regular access of the database with:

  1. kristian@Saturn:~$ psql -U kristian crawler
  2. Welcome to psql 8.2.7, the PostgreSQL interactive terminal.</code>
  4. Type:  \copyright for distribution terms
  5. \h for help with SQL commands
  6. \? for help with psql commands
  7. \g or terminate with semicolon to execute query
  8. \q to quit
  10. crawler=#

My table:

  1. crawler=# \d document;
  2. TABLE "public.document"
  3. COLUMN     |            Type             |                       Modifiers
  4. —————+—————————–+————————
  5. id            | integer                     | NOT NULL DEFAULT NEXTVAL('document_id_seq'::regclass)
  6. url           | text                        | NOT NULL
  7. document      | text                        | NOT NULL
  8. ts_downloaded | timestamp without time zone | DEFAULT now()

Data in the table:

  1. crawler=# select * from document;
  2. id |          url          | document |       ts_downloaded
  3. —-+———————–+———-+—————————-
  4. 1 | | jalla    | 2008-04-19 21:11:11.805482


First thing to get the postgreSQL jdbc driver to work is to add it to the java classpath, and of course copy the actual jar file to its correct location, for instance /usr/lib/jvm/java-6-sun- is my java library path.
My classpath:

  1. /usr/lib/jvm/java-6-sun-

Now its about time to write some actual code:

  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement; </code>
  8. public class DatabaseTest
  9. {
  10. private Connection connection = null;
  12. private static final String USERNAME = "XXXXX";
  13. private static final String PASSWORD = "XXXXX";
  14. private static final String URL = "jdbc:postgresql:";
  15. private static final String DATABASE = "crawler";
  17. public DatabaseTest()
  18. {
  19. try
  20. {
  21. connection = DriverManager.getConnection(URL + DATABASE, USERNAME, PASSWORD);
  22. ResultSet rs = doQuery("SELECT * FROM document");
  25. System.out.println(rs.getString(2));
  26. }
  27. catch (SQLException e)
  28. {
  29. System.out.println("Database Exception!");
  30. System.out.println(e.toString());
  31. e.printStackTrace();
  32. }
  34. }
  36. public ResultSet doQuery(String sql)
  37. {
  38. ResultSet rs;
  39. try
  40. {
  41. Statement stmt = connection.createStatement();
  42. rs = stmt.executeQuery(sql);
  43. return rs;
  44. }
  45. catch (SQLException e) {
  46. e.printStackTrace();
  47. return null;
  48. }
  49. }
  50. }

Trying to execute my script:

  1. kristian@Saturn:~/workspace/crawler$  javac
  2. kristian@Saturn:~/workspace/crawler$  java -Djdbc.drivers=org.postgresql.Driver DatabaseTest

It works :D The installation and initial setup went pretty much by the book, but as a PHP developer I must say that I’m a little bit disappointed, JDBC cannot compare itself to the PHP PDO extension yet. But then again, maybe I just need to get to know the JDBC library better. Anyhow it was fun writing this little java app and refreshing some of my java skills.

Written by Kristian Lunde

May 5th, 2008 at 10:14 pm

Java on Ubuntu

without comments

The other day I decided that it was about time to refresh my java knowledge. I’ve done some java development at work lately, but besides that It has been about 3 years since I last wrote any decent java apps. I have a few ideas of some small cool apps I want to write, but first of all I had to check the java installation on my machine.

Im currently sitting on a Ubuntu 7.04 installation, so I started out by opening my console and typing

java -version

I was a bit surprised about the result, java version could not be determined, I found out that 4 different versions of java were installed and neither the classpath or java_home were set. The java version I wished to used were not among the installed versions. I used the java installation guide on to install my preferred java version, the java 6 version from Sun. The guide was straight forward and the java installation seemed to work as expected after completing the guide.

kristian@Saturn:/usr/lib$ java -version
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)

Looking good. So I tried typing:

kristian@Saturn:/usr/lib$ javac -version
javac: error while loading shared libraries: cannot open shared object file: No such file or directory

Not looking that good, something was wrong :P I googled the result and found my mistake. Earlier while I was trying to get it all together with the 4 different java versions I changed the symlink in /usr/bin/ and I forgot to add the -s when I created the link. Removing the symblink and recreating it did the trick.

kristian@Saturn:/usr/bin$ sudo ln -s /etc/alternatives/javac javac

The javac in /etc/alternatives is a symblink to the current java version. And trying the all famous javac -version now result in the anticipated result:

kristian@Saturn:~$ javac -version
javac 1.6.0_03

Now I’m all set to go and try out my java skills :P

Written by Kristian Lunde

May 2nd, 2008 at 10:04 am

Posted in Java,Linux,Programming

Tagged with ,


without comments

Ever tried to replace a bunch of files with cp -rf some/destination . in linux?

Then you might have had to do a number ‘y’ to confirm the replacement of the already existing files, pretty annoying. Well linux has this marvelous little tool called yes, which automate this process and adds a y after the prompt when replacing a file.

if you just try to type yes in your console you will see that it starts printing ‘y’.

so this is how you actually do it:

yes cp -r some/directory/* .

For more information type man yes in your concole.

Written by Kristian Lunde

April 18th, 2008 at 3:10 pm

Posted in Linux

Tagged with

Get Adobe Flash player