Respect the ~ files

It has been a long time since a post in this blog. I thought to break this silence with a short post.

Several text editors in Linux environment like KWrite and GEdit that will store automatic temporary files ending with a ~ (tilde) character. Generally it is a default setting in most of the major distributions. Initially this feature annoyed me, as now you have twice the number of files in your directory, and often used rm *~ to clear out the files. Although it was annoying at the beginning, there are several cases it saved me. Continue reading

Posted in Humor, Writings | Tagged , | Leave a comment

2013 in review

Like last year here are some stats of this blog for this year from wordpress.com. Worse this year, especially post count is 16, not enough compared to last year post count 24. Lesser visits this year, but some new relatively new posts have caught attention. Hoping to keep the post count at least 2 posts per month on an average on 2014.

The WordPress.com stats helper monkeys prepared a 2013 annual report for this blog.

Here’s an excerpt:

The Louvre Museum has 8.5 million visitors per year. This blog was viewed about 75,000 times in 2013. If it were an exhibit at the Louvre Museum, it would take about 3 days for that many people to see it.

Click here to see the complete report.

Posted in Writings | Tagged | 1 Comment

Generate the process tree of a Linux system

This is a quick post on how to generate a process tree Linux (and *nix) operating systems.

The idea is the same, as in the previous posts: Finding overall and per core CPU utilization and Find process IDs of a running process by name. Read the information present in the /proc/ directory. To get which processes are running we can read the directories with numbers as their names in the /proc/ directory. To generate a process tree we need to establish a process child relationship within the running processes. Each process has a parent (the first generated process is an exception), and it is stored in the process table entry of that process. We need to fetch the parent process id for each running process inorder to establish the tree. Here’s the plan. Continue reading

Posted in Computer Science, Linux Programming | Tagged , , , , , , | Leave a comment

Find process IDs of a running process by name

In this post I will talk about a procedure to find the process IDs of a running process by name, which can then be used to send signals or do other stuffs. For example if you have multiple instances of bash opened, this should be able to get you the list of process IDs (PIDs) of the bash instances.

Firstly, a shell utility is already available called pidof which is a part of the sysvinit-tools package. There are a whole bunch of tools in this package which lets you query PID based on different requirements, send signals to set of processes, etc. Just check out the stuff.

I will only mention the outline of how this is done and post the sourcecodes to do it. After that this can be extended to have many features just like the tools of sysvinit-tools package or more.
Continue reading

Posted in Computer Science, Linux Programming | Tagged , , , , , , , | 1 Comment

Finding overall and per core CPU utilization

Today I will post about how to monitor CPU usage by processor in Linux. As you might have expected this will simply access the CPU time information from /proc pseudo-filesystem and report the results.

The proc filesystem or the Procfs is a special filesystem which gives you a view into the kernel data. No files in procfs exists actually in the disk. There is no disk inodes and thus storage related to the files. Instead of going into procfs I will redirect you to wikipedia: http://en.wikipedia.org/wiki/Procfs. Let’s get in.
Continue reading

Posted in Computer Science, Linux Programming | Tagged , , , , , , | 3 Comments

C Q&A #6: An interesting difference between the C and C++ conditional operator

int main (void)
{
  int a = 5, b = 10, c;

  c = a > 3 ? b = 5 : a = 3;
  printf ("%d %d %d\n", a, b, c);
  //cout << a << " " << b << " " << c << endl;
  
  return 0;
}

Have a look at the above code, what will be the outcome if the code was in C language and if in C++ Language (replace with printf with cout)?

Directly going to the solution. Compilation error for C, and works perfect (no warnings) with C++. I saw this problem is a C question and answer book which didn’t bother to explain, so here is the explanation. Continue reading

Posted in C Language, Computer Science | Tagged , , | 6 Comments

Find pairs of numbers in an array with difference ‘k’

The problem statement is, an long array is given with n elements, we need to find all the pairs of numbers in this long array which have a constant difference k. I will post three methods. The first method is the brute force method and has a runtime complexity O (n2), the next method has runtime complexity O (n*log (n)), and the last one will have the runtime complexity O (n).

Continue reading

Posted in Coding Discussions, Computer Science | Tagged , , , , , , , | Leave a comment

Jumble word solver again

I have already posted a jumbled word solver written in C language, although what I posted is actually become old, as I have changed some of the things in the code. I will update the post with this (hope to update!) with the new changes, but before it I would like to post the the same stuff in other languages and with different datastructure. Recently I am learning Perl and brushing up C++, therefore I will post jumble word solver written in C++ and Perl in this post.
Continue reading

Posted in Coding Discussions, Computer Science | Tagged , , , , , , , , | 1 Comment

Commented!

I couldn’t stop myself from posting this from xkcd, this one is extreme :D

Commented

Commented!


Continue reading

Posted in Humor | Tagged | 2 Comments

Check if a string is rotation of another

There are two strings. We need to find if one string is a rotation of the other. If yes then how many places it was rotated. The solution is pretty straightforward. I will describe two ways in this post. Continue reading

Posted in Coding Discussions, Computer Science | Tagged , , , , | Leave a comment