"tail -f" is a special command in a way that it polls the specified file for any change and prints the new stuff on the fly. It is very helpful in observing logs and any event based data.
Ever wondered how tail achieves this?
"tail" opens the given file and obtains the file-descriptor. It opens it with xfreopen() -> freopen() -> fopen() call. It does its first round of fstat() on the file as well.
Once it has got the fd, it loops infinitely and do the following:
It does fstat() of the file and observes the mtime value. If the mtime value is changes from the last time..it dumps the data. To print the latest data, it lseek() the file to the last reported file size.
Source: http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/tail.c
Wednesday, October 20, 2010
Sunday, September 19, 2010
How touchpad of a laptop work?
It was a curiosity to know the internal details of one of the most used 6x6 cm2 part of a laptop. My curiosity increased with diffrent behavior of the touchpad with different objects. For example, it works well with fingers but a pen, pin, or paper are not entertained.
So how does it work?
It is based on concept of capacitive difference on two parallel plates. Each of these plates have a grid of conductors. When we put our finger on the surface, it creates a charge difference on this surface and the difference of capacitance is sensed by the hardware.
This difference is mapped to mouse motion on our screen.
So how does it work?
It is based on concept of capacitive difference on two parallel plates. Each of these plates have a grid of conductors. When we put our finger on the surface, it creates a charge difference on this surface and the difference of capacitance is sensed by the hardware.
This difference is mapped to mouse motion on our screen.
Thursday, September 16, 2010
MeeGo: Marriage of Nokia and Intel
Nokia and Intel are merging their Linux based intiatives: Meamo and Moblin = Meego
* Open source platform to serve mobiles, notebook, TV, and tablets.
* Hosted under Linux Foundation
* Support x86 and ARM
* Visit http://meego.com for more information
But why would people use this new OS? What's wrong with Andriod? How is it better than Symbion, Android, Windows Mobile or BADA?
We already have Linux based mobile OS, so it'd be hard for this new guy to find a decent place.
* Open source platform to serve mobiles, notebook, TV, and tablets.
* Hosted under Linux Foundation
* Support x86 and ARM
* Visit http://meego.com for more information
But why would people use this new OS? What's wrong with Andriod? How is it better than Symbion, Android, Windows Mobile or BADA?
We already have Linux based mobile OS, so it'd be hard for this new guy to find a decent place.
Monday, September 6, 2010
Uninterrupted Linux session : screen command
Have you ever faced losing connections to a remote machine(e.g. from a putty) and you happened to be in middle of a script that took ten hours to complete. So what would you do??
Restart the script after re-connecting.
Not anymore...
Linux screen solves this problem with providing a terminal that runs on server and just exported to your putty/Terminal client. In simple terms, you are running your putty on remote machine and watching the output on your local client.
Now, if you client goes down, just chill!
Screen is running your script on remote machine.
To start a screen session:
- Login to remote machine with as you may wish.
- Run $screen
- Do you stuff
Power cut and, no net connection and your client is down.
Once power is back, just re-login to remote machine.
and issue:
$screen -r
It'll list all screen sessions running on the remote machine. Get attached to one of the session with:
$session -r
Now,
Restart the script after re-connecting.
Not anymore...
Linux screen solves this problem with providing a terminal that runs on server and just exported to your putty/Terminal client. In simple terms, you are running your putty on remote machine and watching the output on your local client.
Now, if you client goes down, just chill!
Screen is running your script on remote machine.
To start a screen session:
- Login to remote machine with as you may wish.
- Run $screen
- Do you stuff
Power cut and, no net connection and your client is down.
Once power is back, just re-login to remote machine.
and issue:
$screen -r
It'll list all screen sessions running on the remote machine. Get attached to one of the session with:
$session -r
Now,
Saturday, August 21, 2010
Expect Pexpect: Python module to help you automate interactive tests
Many a times we encounter writing a code that requires user input to proceed. Testing and validating such an application can become tedious and frustating. Python implements an elegant solution to cut down the effort needed to "talk to application".
This is called pexpect module, borrowed from Tcl "expect". Pexpect is a tool for controlling and automoating programs. It simple "fools" the application with an user input. It runs the program and monitors the output. When output matches a given pattern, it respond to application mimicking the human intervention.
Pexpect can be extensively used in testing and automation. I found it particularly useful for interacting with application like ssh, ftp, passwd, telnet etc.
It comes packaged with standard Ubuntu 9.10. The version of Python used by me is:
$python --version
Python 2.6.4rc2
This is called pexpect module, borrowed from Tcl "expect". Pexpect is a tool for controlling and automoating programs. It simple "fools" the application with an user input. It runs the program and monitors the output. When output matches a given pattern, it respond to application mimicking the human intervention.
Pexpect can be extensively used in testing and automation. I found it particularly useful for interacting with application like ssh, ftp, passwd, telnet etc.
It comes packaged with standard Ubuntu 9.10. The version of Python used by me is:
$python --version
Python 2.6.4rc2
Subscribe to:
Posts (Atom)