Monday, June 18, 2007
Saturday, June 16, 2007
Which "for loop" works better/faster
I was asked this question in an interview long ago and thought I would post it here.
Which of the following for loop works better assuming no special compiler play, just on programming logic. Will both code pieces execute equally fast?
Which of the following for loop works better assuming no special compiler play, just on programming logic. Will both code pieces execute equally fast?
1 -
for ( i=0; i <10; i++)
for (j=0; j<100; j++)
printf("hello\n");
2 -
for (j=0; j<100; j++)
for ( i=0; i <10; i++)
printf("hello\n");
Thursday, June 14, 2007
Linus likes ZFS, but
Online world is abuzz with discussions on the mail that Linus Torvalds sent to lkmk.org with some seemingly incendiary anti-Sun remarks, and a more cool-headed response by the Sun CEO Jonathan Schwartz. It has sent all the Paris Hilton front page stories down to page 5 to bite the dust. Some things this all seems to imply:
- OpenSolaris has surely begun to ruffle some feathers; even Linus says OpenSolaris' ZFS is something which could make Linux to change its license. That is something!
- The only thing most Linux developers including Linus think OpenSolaris needs Linux for are drivers. Does it imply that if a user can get a machine working with OpenSolaris, there'd be no need to install Linux?
- Linux users want ZFS. Linux developers have started to realize its importance as a Filesystem, but are diverting the issue with licensing and patent issues. Why not directly talk to Sun and implement the stuff? Surely. if FreeBSD and Mac OS X can implement it, so can Linux. It could be that it is harder to port it to Linux and the developers have become lazy.
- Somehow Linus seems to know that "Linux code is _better_". Does it mean he already has peeked into OpenSolaris code and compared it with the Linux before coming to conclusion? That is interesting, and as illuminating as his assertion.
I have a great respect for Linus as is evidenced by one of my earlier posts. But mails like this are uncharacteristic of him. I even feel that it could have been rebuked as FUD-spreading if it had come from someone other, say Microsoft. Hopefully, in the future, Linux and OpenSolaris will be living at peace and users will have choice of an OS not dictated by the license.
- OpenSolaris has surely begun to ruffle some feathers; even Linus says OpenSolaris' ZFS is something which could make Linux to change its license. That is something!
- The only thing most Linux developers including Linus think OpenSolaris needs Linux for are drivers. Does it imply that if a user can get a machine working with OpenSolaris, there'd be no need to install Linux?
- Linux users want ZFS. Linux developers have started to realize its importance as a Filesystem, but are diverting the issue with licensing and patent issues. Why not directly talk to Sun and implement the stuff? Surely. if FreeBSD and Mac OS X can implement it, so can Linux. It could be that it is harder to port it to Linux and the developers have become lazy.
- Somehow Linus seems to know that "Linux code is _better_". Does it mean he already has peeked into OpenSolaris code and compared it with the Linux before coming to conclusion? That is interesting, and as illuminating as his assertion.
I have a great respect for Linus as is evidenced by one of my earlier posts. But mails like this are uncharacteristic of him. I even feel that it could have been rebuked as FUD-spreading if it had come from someone other, say Microsoft. Hopefully, in the future, Linux and OpenSolaris will be living at peace and users will have choice of an OS not dictated by the license.
Wednesday, June 13, 2007
ZFS flavor of the month
A week after Sun CEO Jonathan Schwartz commented that ZFS would be in Leopard, an Apple executive said, "ZFS is not happening", when questioned about ZFS's inclusion in Leopard. Without ZFS announcement in the Apple WWDC, Mac developers would be disappointed and some reporters said they felt sleepy during the keynote.
(Update : Apple has denied the executive's claims and is clarifying that ZFS will be available as a limited option in OS X. See comments on the original story for details.)
ZFS seems to be flavor of the month. While many were expecting Apple to announce it was adding ZFS to Mac OS X, it doesn't seem likely after reading the Apple executive's comment. At least not in the forthcoming release.
In other news, ZFS was reviewed very positively in an InfoWorld article. The editor reviewing the ZFS was all praise for it. "It’s not every day that the computer industry delivers the level of innovation found in Sun's ZFS. More and more advances in the science of IT are based on simply multiplying the status quo. ZFS breaks all the rules here, and it arrives in an amazingly well-thought-out and nicely implemented solution."
Ok that makes up for "late by a year review." One thing that I've observed is that though Sun says ZFS doesn't stand for Zettabyte File System anymore, most reporters still make it a point to expand ZFS that way.
Then, eWEEK gave an Excellence award to ZFS in the E-Business Foundations category. ZFS deserves many such awards and kudos. It has made a big difference in the world of File systems.
(Update : Apple has denied the executive's claims and is clarifying that ZFS will be available as a limited option in OS X. See comments on the original story for details.)
ZFS seems to be flavor of the month. While many were expecting Apple to announce it was adding ZFS to Mac OS X, it doesn't seem likely after reading the Apple executive's comment. At least not in the forthcoming release.
In other news, ZFS was reviewed very positively in an InfoWorld article. The editor reviewing the ZFS was all praise for it. "It’s not every day that the computer industry delivers the level of innovation found in Sun's ZFS. More and more advances in the science of IT are based on simply multiplying the status quo. ZFS breaks all the rules here, and it arrives in an amazingly well-thought-out and nicely implemented solution."
Ok that makes up for "late by a year review." One thing that I've observed is that though Sun says ZFS doesn't stand for Zettabyte File System anymore, most reporters still make it a point to expand ZFS that way.
Then, eWEEK gave an Excellence award to ZFS in the E-Business Foundations category. ZFS deserves many such awards and kudos. It has made a big difference in the world of File systems.
Tuesday, June 12, 2007
Sunday, June 10, 2007
Links and symlinks - Unix and Windows
Hard links in Unix are files that have different names and can possibly different directories, but they have same inode i.e. the file is stored at any one place in the hard disk. All the hard links to any file point to that location. One can delete a hard link but it won't delete the file if there is any other link to it.
Symbolic links or symlinks on the other hand are small file that contain the pointer to another file. They are different from the actual file they are pointing to. So deleting a symbolic link won't delete the actual file. The implementation of symbolic links in Unix is transparent to the user. If a user opens and edits a symbolic link, he actually is editing the file the symbolic link points to. The symbolic link remains just a pointer to the actual file.
While Windows have shortcuts that are nearest thing to symbolic links, if someone edits a shortcut file, it actually gets changed and so it is not as transparent to the user as Unix. I read somewhere that Windows Vista has introduced transparent symbolic links similar to Unix.
Symbolic links or symlinks on the other hand are small file that contain the pointer to another file. They are different from the actual file they are pointing to. So deleting a symbolic link won't delete the actual file. The implementation of symbolic links in Unix is transparent to the user. If a user opens and edits a symbolic link, he actually is editing the file the symbolic link points to. The symbolic link remains just a pointer to the actual file.
While Windows have shortcuts that are nearest thing to symbolic links, if someone edits a shortcut file, it actually gets changed and so it is not as transparent to the user as Unix. I read somewhere that Windows Vista has introduced transparent symbolic links similar to Unix.
Saturday, June 9, 2007
Core Solaris kernel paths
Sometime back I was searching online the path for core kernel binaries for Solaris but the information was hard to find and it was not exhaustive. Finally I was able to find the information in Solaris Internals book. The paths for core Solaris kernel binaries are:
/kernel/genunix - Platform independent core kernel for non-UltraSparc based systems resides in this binary. All non-UltraSparc based systems load this genunix during boot time.
/platform/sun4u/kernel/genunix - optimized binary for UltraSparc, but it is independent of the system type. This binary is loaded during boot time only by UltraSparc systems.
/platform/{arch}/ kernel/unix - Platform dependent component of the core kernel resides here. {arch} is the architecture of the system.
The other kernel modules get loaded on demand later i.e. when an application requires them. They reside under the /usr directory tree.
All these binaries contain various low level kernel services that are needed to run the system. The command to find all the kernel modules in a system is
# modinfo
It will give as output the loaded modules in a running system.
/kernel/genunix - Platform independent core kernel for non-UltraSparc based systems resides in this binary. All non-UltraSparc based systems load this genunix during boot time.
/platform/sun4u/kernel/genunix - optimized binary for UltraSparc, but it is independent of the system type. This binary is loaded during boot time only by UltraSparc systems.
/platform/
The other kernel modules get loaded on demand later i.e. when an application requires them. They reside under the /usr directory tree.
All these binaries contain various low level kernel services that are needed to run the system. The command to find all the kernel modules in a system is
# modinfo
It will give as output the loaded modules in a running system.
Friday, June 8, 2007
Going from JDS to CDE
I have started using CDE now for Solaris. JDS was becoming a pain with its sluggish pace. It was eating a lot of memory, too. CDE seems lightweight in this regard as compared to JDS. There are a lot of things in CDE that I wish were more JDS-like. I will try to configure and see how friendly I can make it for general pupose use. It will be used for web-browsing and mails.
The main difference between CDE and JDS when one begins using CDE after a long time with other desktops is how the minimize windows feature works, and icons on the desktop that are absent in CDE. On minimizing any window, it appears as an icon on the desktop, unlike JDS's "go to bottom panel behavior."
The responsiveness of CDE is much better than JDS though and that is what sets it apart.
The main difference between CDE and JDS when one begins using CDE after a long time with other desktops is how the minimize windows feature works, and icons on the desktop that are absent in CDE. On minimizing any window, it appears as an icon on the desktop, unlike JDS's "go to bottom panel behavior."
The responsiveness of CDE is much better than JDS though and that is what sets it apart.
Tuesday, June 5, 2007
Creating a dynamic library - example
We all use library functions in the programs we write. An example of library that is always used in Solaris and Unix like Operating systems is libc.so. But how to create a library? It is not hard. A dynamic library can be easily created as shown in the following example.
Let's say we want to create a library called libgeek.so. It will contain an example function called my_library_func() that we will use in our program. We will create a simple program called geek.c that has the function we wanted. We will compile this as a library and call it libgeek.so (library names begin with lib) :
$ cat geek.c
my_library_func()
{
printf("Inside my library function");
}
The above is a library function we wanted to create. We then compile it into a dynamic library by giving a -G option to compiler :
$ cc -o libgeek.so -G geek.c
Now, we can use the generated library libgeek.so in our programs like:
$ cat hellolibrary.c
int main()
{
my_library_func();
return 0;
}
Now, we can compile our program and tell the linker to link to the library we created for my_library_func() :
$ cc hellolibrary.c -L/home/osgeek -R/home/osgeek -lgeek
L and R tell linker the path to look up during link-time and run-time to find library libgeek.so. The library libgeek.so is used with "lib" part removed and "l" prefixed as "lgeek".
When we run this program, the output would look like:
$ a.out
Inside my library function
That's it. We created a library and used it in a program.
Let's say we want to create a library called libgeek.so. It will contain an example function called my_library_func() that we will use in our program. We will create a simple program called geek.c that has the function we wanted. We will compile this as a library and call it libgeek.so (library names begin with lib) :
$ cat geek.c
my_library_func()
{
printf("Inside my library function");
}
The above is a library function we wanted to create. We then compile it into a dynamic library by giving a -G option to compiler :
$ cc -o libgeek.so -G geek.c
Now, we can use the generated library libgeek.so in our programs like:
$ cat hellolibrary.c
int main()
{
my_library_func();
return 0;
}
Now, we can compile our program and tell the linker to link to the library we created for my_library_func() :
$ cc hellolibrary.c -L/home/osgeek -R/home/osgeek -lgeek
L and R tell linker the path to look up during link-time and run-time to find library libgeek.so. The library libgeek.so is used with "lib" part removed and "l" prefixed as "lgeek".
When we run this program, the output would look like:
$ a.out
Inside my library function
That's it. We created a library and used it in a program.
Saturday, June 2, 2007
Firefox Add-on - Split browser
I've recently started using Split browser Add-on for Firefox browser and am greatly impressed with it. It adds value to my browsing experience. No need to switch to another tab when I want to reference something in a different page. I can look at both pages together by splitting the current browser window in any way I want - Left, Right, Top, Bottom. Once done, I can gather all the split windows to old style tabs. Tab that is currently open can also be split horizontally or vertically.
On a related note, I un-installed the Cooliris Add-on I had installed about a month ago. While it did look useful in the beginning, it was becoming too obtrusive and an annoyance, especially when there were links very near to each other. Trying to open a link would bring up a preview of another link. Also, I was using it less and less. Good-bye Cooliris, Hi, Split broswer!
On a related note, I un-installed the Cooliris Add-on I had installed about a month ago. While it did look useful in the beginning, it was becoming too obtrusive and an annoyance, especially when there were links very near to each other. Trying to open a link would bring up a preview of another link. Also, I was using it less and less. Good-bye Cooliris, Hi, Split broswer!
Subscribe to:
Posts (Atom)
Steps to install PyTorch on VMware workstation (Ubuntu guest)
The following is the list of steps to install pytorch 2.0 in VMware workstation (Ubuntu guest): $ mkdir ~/pytorch $ mkdir ~/pytorch/as...
-
Recently one of my computers' Linux partition was deleted by mistake. As the Linux partition held the multi-boot information, it made th...
-
Most wannabe geeks would say Linux, though it is just a kernel and not an OS. Some would answer Ubuntu or Gentoo depending on which is the &...
-
Here is a probabilistic solution to the two General's problem; it gives a high probability of succcess if the number of messages(messeng...