Sticky bit

Sticky bit on files
Sticky bit can be set on files for faster loading of program which in turn reduces the delay in execution of the binary. When a process executes a file that has its sticky bit set, the kernel does not release the memory allocated for text when it later detaches the region during exit or exec, even if the region reference count drops to 0. the kernel leaves the text region intact with inode reference count 1, even though it is no longer attached to any process. When another process execs the file, it finds the region table entry for the file text.
The process startup time is small, because it does not have to read the text from file system. If the text is still in momory, the kernel does not do any I/O for the text; if the kernel has swapped the text to a swap device, it is faster to load the text from swap device than from the file system.

As per some articles, this feature is is of no use because, with the evolution of technology, fast memory access techniques evolved which kind of obsoleted the requirement of sticky bit for for faster loading of programs.

Eg:
[root@iwf1114163 testdir]# touch testfile
[root@iwf1114163 testdir]# ll
total 0
-rw-r–r– 1 root root 0 Sep 3 11:14 testfile
[root@iwf1114163 testdir]# chmod +t testfile
[root@iwf1114163 testdir]# ll
total 0
-rw-r–r-T 1 root root 0 Sep 3 11:14 testfile
[root@iwf1114163 testdir]# chmod -t testfile
[root@iwf1114163 testdir]# ll
total 0
-rw-r–r– 1 root root 0 Sep 3 11:14 testfile
[root@iwf1114163 testdir]# chmod 1544 testfile
[root@iwf1114163 testdir]# ll
total 0
-r-xr–r-T 1 root root 0 Sep 3 11:14 testfile
[root@iwf1114163 testdir]# chmod 555 testfile
[root@iwf1114163 testdir]# ll
total 0
-r-xr-xr-x 1 root root 0 Sep 3 11:14 testfile
[root@iwf1114163 testdir]# chmod +t testfile
[root@iwf1114163 testdir]# ll
total 0
-r-xr-xr-t 1 root root 0 Sep 3 11:14 testfile

For setting the sticky bit either of the following command can be used
chmod +t testfile
chmod 1544 testfile

To remove the sticky bit
chmod -t testfile
chmod 544 testfile

If both execute bit and sticky bit are set, ‘t’ will be the permission bit
If only sticky bit is set, ‘T’ will be the permission bit

——–t Sticky bit and other execute bit are both set.
——–T Sticky bit is set and other execute bit is not set.

Sticky bit on directories
The sticky bit is a permission bit that protects the files within a directory. If the directory has the sticky bit set, a file can be deleted only by the owner of the file, the owner of the directory, or by root. This special permission prevents a user from deleting other users’ files from public directories such as /tmp
/tmp directory in unix has sticky bit set. Any user can create files under this directory. But only root or owner of the file can delete/rename the files under this directory.

Eg:
[root@iwf1114163 /]# mkdir tmp3
[root@iwf1114163 /]# chmod +t tmp3
[root@iwf1114163 /]# ls -l tmp3
drwxrwxrwt 2 root root 6 Sep 3 11:22 tmp3
[root@iwf1114163 /]# cd tmp3
[root@iwf1114163 tmp3]# su nan1
[nan1@iwf1114163 tmp3]$ touch nan1-file
[nan1@iwf1114163 tmp3]$ ll
total 0
-rw-rw-r– 1 nan1 nan1 0 Sep 3 11:23 nan1-file
[nan1@iwf1114163 tmp3]$ exit
exit
[root@iwf1114163 tmp3]# su nan2
[nan2@iwf1114163 tmp3]$ rm nan1-file
rm: remove write-protected regular empty file ânan1-fileâ? y
rm: cannot remove ânan1-fileâ: Operation not permitted
[nan2@iwf1114163 tmp3]$

If both execute bit and sticky bit are set, ‘t’ will be the permission bit
If only sticky bit is set, ‘T’ will be the permission bit

——–t Sticky bit and other execute bit are both set.
——–T Sticky bit is set and other execute bit is not set.

References
1. http://www.thegeekstuff.com/2011/02/sticky-bit-on-directory-file/
2. The design of the unix operating system by Maurice J.bach
3. https://docs.oracle.com/cd/E19683-01/806-4078/secfiles-69/index.html
4. http://foralllinux.blogspot.in/2013/04/set-setuid-setgid-and-sticky-bit-in.html

Advertisements
Posted in Unix and Unix Internals | Leave a comment

Three Thousand Stiches

by Sudha Murty
What a wonderful book. Every chapter of the book is an interesting read. Most of the content in book is about Infosys foundation and the work done by it. Most of us think, running an NGO/charitable organization is a easy task but Sudha madam has explained the difficulties of running the organization. Couple of chapters are on personal life of author, which are also interesting.
Book is about the real life difficulties/problems/issues which most of us many not be aware of or cannot imagine can people/life be so cruel but that’s the reality i think.

I am sure whoever starts reading the book wil complete it without leaving any chapter. This is the first book of the author i have read which has inspired to read more books of the author.

Happy Reading!!!

Posted in General Books | Leave a comment

Executing commands on windows host from unix host

Many a times we may need to execute commands in host#2 from host#1, where in host#1 and host#2 can be windows or unix hosts. In this post I will be providing information on how to run commands from unix host (host#1) which gets executed on host#2 which can be a windows or unix host.

If host#2 is a unix host sshpass command be used on host#1 to execute commands on host#2. sshpass can be downloaded here
If host#2 is a windows host, winexe command can be used to host#1 to execute commands on host#2. Winexe can be downloaded here.

Both sshpass and winexe will be installed in host#1 and nothing needs to be installed in host#2. Commands gets executed on host#2 and any output will be displayed in host#1 which can be used for any further processing.

Posted in General Tech Discussion | Leave a comment

Zero to One

by Peter Thiel with Blake Masters. This book is all about startups.
What is zero to one ?. Creating something which does not exist is zero to one. Replicating an existing thing is one to N which is a wonderful concept. Startup’s always work form 0 to 1 and as such the name of book. Author has explained various things about how startup operate, how do they build product with minimum value proposition, releasing the product to market and various other stuff. Book also has some details about past 1998-2000 dot com boom where in everyone was willing to join a startup or start his own and what eventually led to the .com burst.

Author has explained couple of important things about founders and co-founders of company. Choosing co-founders while starting a company is very crucial. If the frequency of the founders does not match, company will cease to exist in future because of difference in opinion between founders. If one is joining a startup again it’s important to analyze the founding members to avoid undue risk in future. Also explained in detail are salary of founders and stock options provided to founders and employees and what could be worth of the stocks in future.

Overall a good book to read.

Posted in General Books | Leave a comment

The Lean Startup

An interesting book on how startup’s work. Some of the concepts like “Pivot or Preserve” and five ‘Y’ concepts can be adopted in general in any situation and is not unique to a startup company. Also most of the concepts, in general can be applied in all projects in large organizations too. It just needs a change the way the projects are managed. Even though i work in large organization, I adopted Minimum Value Proposition (MVP) and iterative model in one of the projects and it really worked well. One of the other notable thing which i remember is, office politics in large organizations – allocation of budget.
Recently read bad news about “Kqingdom ITES Pvt Ltd”. So entrepreneur should be very careful not to be obsessed with their idea and should decide on right time whether to pivot or preserve.

Book is worth a read for all.

Posted in Personality Development Books | Leave a comment

Java The Complete Reference, 9th Edition

I did search for 9th edition of book and is available for download only as torrent. If you don’t have access to torrent sites, do email me ( iamnandans@gmail.com ) , i will send it across. Download the example programs in book from here.

Posted in Tech Books to Read | Leave a comment

The Obstacle is the Way

By Ryan Holiday

Everybody faces obstacles in life. How individuals reacts to the obstacle, how does he/she over comes the obstacle differentiates the individual from rest. Author has provided numerous examples of renowned individuals, obstacles they faced and how did they overcome them turning obstacles into advantages. It’s all about how individuals perceives the obstacle. When one overcomes obstacle, he/she learns various lessons as part it which will be stepping stop to success. Never ever think, if current problem is solved everything is solved. God has designed the universe in such a way that, next obstacle is ready to hit us. So obstacles are part of life. Don’t run away from them instead resolve them and move forward. “Prepare to start Again” is a must chapter to be read.

It’s a good motivation book especially if one is going through rough patch in life. I did like the book, hope others will.

Posted in Personality Development Books | Leave a comment