Ubuntu: How to check implementation details of 'watch' command?



Question:

To maximise learning I ended up cloning whole linux source code from github. I wanted to check how 'watch' command is implemented in it, but code is just too vast to return anything useful when I try to grep 'watch'. I was wondering if any of you can help.


Solution:1

In addition.

It is in the procps package.

For example if you search the man pages of ubuntu it will normally say what package provides the code. (Like this)

The source code can be found (here).

Direct Download: http://procps.sourceforge.net/procps-3.2.8.tar.gz

or you could use dpkg to see what package owns a particular file like so:

dpkg -S /usr/bin/watch  


Find source code for any command:

So if say you wanted to look at top source code you could:

whereis top  

enter image description here

The binary file for top is "/usr/bin/top" and to find the package that owns that file:

dpkg -S /usr/bin/top  

enter image description here

Make sure to:

sudo apt-get install dpkg-dev  

And then you can find the source code for a package by:

sudo apt-get source procps  sudo apt-get source gedit  sudo apt-get source <package-name>  

It will download a tar in the current directory and extract it:

result of apt-get source

We should then be able to find the source code for how it works:

how to download source code for a command


Solution:2

May be you could start-off by strace watch.

From the manual page of strace:

   strace is a useful diagnostic, instructional, and debugging tool.  Sys‐     tem  administrators,  diagnosticians  and trouble-shooters will find it     invaluable for solving problems with programs for which the  source  is     not  readily available since they do not need to be recompiled in order     to trace them.  Students, hackers and the overly-curious will find that     a  great  deal  can  be  learned about a system and its system calls by     tracing even ordinary programs.  And programmers will find  that  since     system  calls  and  signals  are  events that happen at the user/kernel     interface, a close examination of this boundary is very useful for  bug     isolation, sanity checking and attempting to capture race conditions.  

For the actual implementation details, you will ultimately have to rely on the source code. You can take the help of tools like csope and ctags.


Solution:3

I think this link might help. I just Google for watch.c


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »