Friday, July 22, 2011
http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch07_:_The_Linux_Boot_Process
http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch07_:_The_Linux_Boot_Process
RPM usage
# rpm -ivh foo-2.0-4.i386.rpm
# rpm -i ftp://ftp.redhat.com/pub/redhat/RPMS/foo-1.0-1.i386.rpm
# rpm -i http://oss.oracle.com/projects/firewire/dist/files/kernel-2.4.20-18.10.1.i686.rpm
Used to install a RPM package. Note that RPM packages have file naming conventions like foo-2.0-4.i386.rpm , which include the package name (foo), version (2.0), release (4), and architecture (i386). Also notice that RPM understands FTP and HTTP protocols for installing and querying remote RPM files.
# rpm -e foo
To uninstall a RPM package. Note that we used the package name foo , not the name of the original package file foo-2.0-4.i386.rpm above.
# rpm -Uvh foo-1.0-2.i386.rpm
# rpm -Uvh ftp://ftp.redhat.com/pub/redhat/RPMS/foo-1.0-1.i386.rpm
# rpm -Uvh http://oss.oracle.com/projects/firewire/dist/files/kernel-2.4.20-18.10.1.i686.rpm
To upgrade a RPM package. Using this command, RPM automatically uninstall the old version of the foo package and install the new package. It is safe to always use rpm -Uvh to install and upgrade packages, since it works fine even when there are no previous versions of the package installed! Also notice that RPM understands FTP and HTTP protocols for upgrading from remote RPM files.
# rpm -qa
To query all installed packages . This command will print the names of all installed packages installed on your Linux system.
# rpm -q foo
To query a RPM package . This command will print the package name, version, and release number of the package foo only if it is installed. Use this command to verify that a package is or is not installed on your Linux system.
# rpm -qi foo
To display package information . This command display package information including the package name, version, and description of the installed program. Use this command to get detailed information about the installed package.
# rpm -ql foo
To list files in installed package . This command will list all of files in an installed RPM package. It works only when the package is already installed on your Linux system.
# rpm -i ftp://ftp.redhat.com/pub/redhat/RPMS/foo-1.0-1.i386.rpm
# rpm -i http://oss.oracle.com/projects/firewire/dist/files/kernel-2.4.20-18.10.1.i686.rpm
Used to install a RPM package. Note that RPM packages have file naming conventions like foo-2.0-4.i386.rpm , which include the package name (foo), version (2.0), release (4), and architecture (i386). Also notice that RPM understands FTP and HTTP protocols for installing and querying remote RPM files.
# rpm -e foo
To uninstall a RPM package. Note that we used the package name foo , not the name of the original package file foo-2.0-4.i386.rpm above.
# rpm -Uvh foo-1.0-2.i386.rpm
# rpm -Uvh ftp://ftp.redhat.com/pub/redhat/RPMS/foo-1.0-1.i386.rpm
# rpm -Uvh http://oss.oracle.com/projects/firewire/dist/files/kernel-2.4.20-18.10.1.i686.rpm
To upgrade a RPM package. Using this command, RPM automatically uninstall the old version of the foo package and install the new package. It is safe to always use rpm -Uvh to install and upgrade packages, since it works fine even when there are no previous versions of the package installed! Also notice that RPM understands FTP and HTTP protocols for upgrading from remote RPM files.
# rpm -qa
To query all installed packages . This command will print the names of all installed packages installed on your Linux system.
# rpm -q foo
To query a RPM package . This command will print the package name, version, and release number of the package foo only if it is installed. Use this command to verify that a package is or is not installed on your Linux system.
# rpm -qi foo
To display package information . This command display package information including the package name, version, and description of the installed program. Use this command to get detailed information about the installed package.
# rpm -ql foo
To list files in installed package . This command will list all of files in an installed RPM package. It works only when the package is already installed on your Linux system.
Thursday, July 7, 2011
Source Code Browsing In Linux-CTAGS usage
How to use ctags command in linux? explained in simple steps.
CTAGS is a good utility for source code browsing in Linux through vi editor. To use ctags , at the source code directory enter
# ctags -uR *
This will create tags file in the source code.
Open a file in that source code using vi editor & set the tags file for that file using " ESC + :set tags=tags" ( path of tags file . if it is at different level then give the entire path like ../tags or ../../tags ).
Once the tag file is set for that file, then you can look the at function definitions, variable declarations, .......... by placing the cursor on that function call or variable & press "CRTL + }" and for coming back to same place press "CTRL + t" key sequence.
Follow CTAGS documentation for more insigh
CTAGS is a good utility for source code browsing in Linux through vi editor. To use ctags , at the source code directory enter
# ctags -uR *
This will create tags file in the source code.
Open a file in that source code using vi editor & set the tags file for that file using " ESC + :set tags=tags" ( path of tags file . if it is at different level then give the entire path like ../tags or ../../tags ).
Once the tag file is set for that file, then you can look the at function definitions, variable declarations, .......... by placing the cursor on that function call or variable & press "CRTL + }" and for coming back to same place press "CTRL + t" key sequence.
Follow CTAGS documentation for more insigh
Steps For Generating Document On Doxygen
Generating Document using doxygen
In simple Steps.
1) In every (.c or .h) file put this comment after includes.
---------------------------------------------------------------------
/** \file filename.ext
* \brief some notes about this file.
*
* A more extensive description of this file.
*/
Example:
/** \file function.h
* \brief This file contains prototypes for functions defined in function.c.
*
* This file contains prototypes for functions defined in function.c.
*
*/
NOTE: Period '.' is necessary after \brief sentence.
2) Before every function put this comment:
---------------------------------------------------
/** \brief A brief description of my_function().
*
* A more extensive description of my_function().
*
* \param aParameter A brief description of aParameter.
* \param bParameter B brief description of bParameter.
* \return A brief description of what myProcedure() returns.
*/
Example:
/** \brief get position of field in configfile.
*
* This function returns the position of the
* field in the config file………………….
* ………………………………………....
*
* \param i index of field.
*
* \return returns position of the field in configfile.
*
*/
3)Just before each variable, put these comments.
------------------------------------------------------------
Example:
/** \brief A brief description of myVariable.
*
* A more extensive description of myVariable.
*/
int myVariable;
Note: use it only for important variables:
4)Just before each enumeration put these comments.
----------------------------------------------------------------
/**
* \enum some description about this enum.
*/
Beside each field write some description inside /**< description */
Example:
enum Fields {
Factory_State, /**< Factory State Flag */
Login_Password, /**< Password required to login */
Model_Name, /**< Model Name of the SerialServer */
MAC_Address, /**< MAC Address of the SerialServer */
. . . .
};
5)Just before each structure put these comments ------------------------------------------------------------
/**
* \struct some description about this enum.
*/
beside each field write some description inside /**< description */
Example:
struct nw2serial_s {
struct mcs7840 * mcs7840_dev; /**< serial device structure */
spinlock_t lock; /**< spinlock for list operations */
unsigned char number; /**< unknown */
. . . . .
};
Note: for enum and typedef just change the \struct tag to \enum or \typedef.
Project Description for main page:
--------------------------------------------
In main file. keep this description at the beginning of file.
/*
* \mainpage
* write description here.
*
*
*
*/
For TODO put this comment:
-----------------------------------
/**
* \todo keep todo description here.
*
*/
For more doxygen tags manual Creating documents:
cd to the directory containing source files and type.
$doxygen –g
example:
$doxygen -g ssdoc
This will create a configuration file called ssdoc.
Open ssdoc and modify it.
Set the tags PROJECT_NAME , PROJECT_NUMBER
Example:
PROJECT_NAME = MCS8140-SS-16S
PROJECT_NUMBER = 1.0.0.2
If you want header, footer and CSS files then run
$doxygen –w html header.html footer.html stylesheet.css
This will create header.html , footer.html and doxygen.css files,
now set paths for HTML_HEADER, HTML_FOOTER, and HTML_STYLESHEET tags in configuration file (ssdoc)
example
HTML_HEADER = header.html
HTML_FOOTER = footer.html
HTML_STYLESHEET = doxygen.css
finally run doxygen.
$doxygen ssdoc
This will create two folders ./html and ./latex
For html document open ./html/index.html file.
To get an image above the document modify the header.html file and run doxygen again.
Example:
Modify css to get different colors.
Creating PDF document:
--------------------------------------
To create pdf document just cd to ./latex folder
and type
$make
This will create a pdf refman.pdf in ./latex folder.
In simple Steps.
1) In every (.c or .h) file put this comment after includes.
---------------------------------------------------------------------
/** \file filename.ext
* \brief some notes about this file.
*
* A more extensive description of this file.
*/
Example:
/** \file function.h
* \brief This file contains prototypes for functions defined in function.c.
*
* This file contains prototypes for functions defined in function.c.
*
*/
NOTE: Period '.' is necessary after \brief sentence.
2) Before every function put this comment:
---------------------------------------------------
/** \brief A brief description of my_function().
*
* A more extensive description of my_function().
*
* \param aParameter A brief description of aParameter.
* \param bParameter B brief description of bParameter.
* \return A brief description of what myProcedure() returns.
*/
Example:
/** \brief get position of field in configfile.
*
* This function returns the position of the
* field in the config file………………….
* ………………………………………....
*
* \param i index of field.
*
* \return returns position of the field in configfile.
*
*/
3)Just before each variable, put these comments.
------------------------------------------------------------
Example:
/** \brief A brief description of myVariable.
*
* A more extensive description of myVariable.
*/
int myVariable;
Note: use it only for important variables:
4)Just before each enumeration put these comments.
----------------------------------------------------------------
/**
* \enum some description about this enum.
*/
Beside each field write some description inside /**< description */
Example:
enum Fields {
Factory_State, /**< Factory State Flag */
Login_Password, /**< Password required to login */
Model_Name, /**< Model Name of the SerialServer */
MAC_Address, /**< MAC Address of the SerialServer */
. . . .
};
5)Just before each structure put these comments ------------------------------------------------------------
/**
* \struct some description about this enum.
*/
beside each field write some description inside /**< description */
Example:
struct nw2serial_s {
struct mcs7840 * mcs7840_dev; /**< serial device structure */
spinlock_t lock; /**< spinlock for list operations */
unsigned char number; /**< unknown */
. . . . .
};
Note: for enum and typedef just change the \struct tag to \enum or \typedef.
Project Description for main page:
--------------------------------------------
In main file. keep this description at the beginning of file.
/*
* \mainpage
* write description here.
*
*
*
*/
For TODO put this comment:
-----------------------------------
/**
* \todo keep todo description here.
*
*/
For more doxygen tags manual Creating documents:
cd to the directory containing source files and type.
$doxygen –g
example:
$doxygen -g ssdoc
This will create a configuration file called ssdoc.
Open ssdoc and modify it.
Set the tags PROJECT_NAME , PROJECT_NUMBER
Example:
PROJECT_NAME = MCS8140-SS-16S
PROJECT_NUMBER = 1.0.0.2
If you want header, footer and CSS files then run
$doxygen –w html header.html footer.html stylesheet.css
This will create header.html , footer.html and doxygen.css files,
now set paths for HTML_HEADER, HTML_FOOTER, and HTML_STYLESHEET tags in configuration file (ssdoc)
example
HTML_HEADER = header.html
HTML_FOOTER = footer.html
HTML_STYLESHEET = doxygen.css
finally run doxygen.
$doxygen ssdoc
This will create two folders ./html and ./latex
For html document open ./html/index.html file.
To get an image above the document modify the header.html file and run doxygen again.
Example:
Modify css to get different colors.
Creating PDF document:
--------------------------------------
To create pdf document just cd to ./latex folder
and type
$make
This will create a pdf refman.pdf in ./latex folder.
Wednesday, July 6, 2011
How to change MAC address in Linux
First find the physical MAC address of your machine by running the following command :
$ ifconfig -a | grep HWaddr
eth0 Link encap:Ethernet HWaddr 00:80:48:BA:d1:20
The hexadecimal numbers in blue denote my machine's MAC address. Yours will be different. Learn how to use the ifconfig Linux command.
Next, login as root in Linux and enter the following commands -
# ifconfig eth0 down
# ifconfig eth0 hw ether 00:80:48:BA:d1:30
# ifconfig eth0 up
# ifconfig eth0 |grep HWaddr
Note above that I have changed the MAC address to a different number highlighted in blue. 00:80:48:BA:d1:30 is the new MAC address I have provided for my Linux machine. You can choose any 48 bits hexadecimal address as your MAC address.
Why you should change MAC address of your Linux machine
These are the reasons you should change the MAC address of your machine.
* For privacy - For instance when you are connecting to a Wi-Fi hotspot.
* To ensure interoperability. Some internet service providers bind their service to a specific MAC address; if the user then changes their network card or intends to install a router, the service won't work anymore. Changing the MAC address of the new interface will solve the problem.
$ ifconfig -a | grep HWaddr
eth0 Link encap:Ethernet HWaddr 00:80:48:BA:d1:20
The hexadecimal numbers in blue denote my machine's MAC address. Yours will be different. Learn how to use the ifconfig Linux command.
Next, login as root in Linux and enter the following commands -
# ifconfig eth0 down
# ifconfig eth0 hw ether 00:80:48:BA:d1:30
# ifconfig eth0 up
# ifconfig eth0 |grep HWaddr
Note above that I have changed the MAC address to a different number highlighted in blue. 00:80:48:BA:d1:30 is the new MAC address I have provided for my Linux machine. You can choose any 48 bits hexadecimal address as your MAC address.
Why you should change MAC address of your Linux machine
These are the reasons you should change the MAC address of your machine.
* For privacy - For instance when you are connecting to a Wi-Fi hotspot.
* To ensure interoperability. Some internet service providers bind their service to a specific MAC address; if the user then changes their network card or intends to install a router, the service won't work anymore. Changing the MAC address of the new interface will solve the problem.
Saturday, July 2, 2011
ping
One of the most recognized utilities is the ping command. The ping command
can be used in your IP network to assist in determining whether or not an IP
addressed node is reachable.
ping sends an echo request within an Internet Control Message Protocol
(ICMP) packet. Once the echo request has been sent, the device that sent the
ping will monitor for a reply to the echo request. Once the reply is received,
the results are measured and the following statistics are recorded and printed
on the screen:
Packet loss (if any)
The time it takes for the data to make a round trip (to and from the
destination or target node)
Statistics gathered during the ping session
Here is an example of a typical11 successful ping session:
C:\>ping 64.233.167.99
Pinging 64.233.167.99 with 32 bytes of data:
Reply from 64.233.167.99: bytes=32 time=44ms TTL=235
Reply from 64.233.167.99: bytes=32 time=38ms TTL=235
Reply from 64.233.167.99: bytes=32 time=37ms TTL=236
Reply from 64.233.167.99: bytes=32 time=37ms TTL=235
Ping statistics for 64.233.167.99:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 37ms, Maximum = 44ms, Average = 39ms
In the example, the host issues an echo request to the target IP and
received the reply. The reply was 32 bytes in size. There were a total of four
echo request packets sent with 100 percent success. The average round trip
was 39 ms.
Unfortunately, because of our friends the ‘‘Ker’’ brothers (see Chapter 14),
many network administrators are now setting filters to not accept the IGMP
echo request packets. This choice is mainly because of the growing con-
cern of Internet worms that use ping to locate nodes that they can attack.
By not accepting the echo requests, the node is less vulnerable to attacks
than if it did accept them. This makes the ping utility useless when try-
ing to troubleshoot issues with the filtered interface and therefore may lead
to misleading diagnosis of problems in the network. Also keep in mind that
filtering these packets is only an annoyance for the Kers . . . they can still get to
the interface if they really want to.
The format of the ICMP echo request and reply packets are shown in
Figure 16-1.
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
Type Code Checksum
Identifier Sequence Number
Data
Figure 16-1 The ICMP echo reply/request datagram format
As mentioned already, the ICMP echo reply is returned for any ICMP echo
requests that are sent to the target node. The target node must respond to
echo requests when it can, and the reply will contain the data that was sent
to it from the originating node.
The echo request datagram type will be set to 8.12
The echo reply will have a datagram type set to 0.
The code field will be set to 0 for both the request and reply.
The Identifier and the Sequence number fields are used to
ensure that the proper reply is sent to the proper request.
The data field in the request and reply must contain the same data.
The ping command will also give you an idea of what the problem may be
when you are not able to get a valid response as shown in the example below.
The two error messages that you may receive when you are not able to reach
your target are:
Request timed out: There was no reply from the host.
Destination host unreachable: There is no route to the destination.
can be used in your IP network to assist in determining whether or not an IP
addressed node is reachable.
ping sends an echo request within an Internet Control Message Protocol
(ICMP) packet. Once the echo request has been sent, the device that sent the
ping will monitor for a reply to the echo request. Once the reply is received,
the results are measured and the following statistics are recorded and printed
on the screen:
Packet loss (if any)
The time it takes for the data to make a round trip (to and from the
destination or target node)
Statistics gathered during the ping session
Here is an example of a typical11 successful ping session:
C:\>ping 64.233.167.99
Pinging 64.233.167.99 with 32 bytes of data:
Reply from 64.233.167.99: bytes=32 time=44ms TTL=235
Reply from 64.233.167.99: bytes=32 time=38ms TTL=235
Reply from 64.233.167.99: bytes=32 time=37ms TTL=236
Reply from 64.233.167.99: bytes=32 time=37ms TTL=235
Ping statistics for 64.233.167.99:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 37ms, Maximum = 44ms, Average = 39ms
In the example, the host issues an echo request to the target IP and
received the reply. The reply was 32 bytes in size. There were a total of four
echo request packets sent with 100 percent success. The average round trip
was 39 ms.
Unfortunately, because of our friends the ‘‘Ker’’ brothers (see Chapter 14),
many network administrators are now setting filters to not accept the IGMP
echo request packets. This choice is mainly because of the growing con-
cern of Internet worms that use ping to locate nodes that they can attack.
By not accepting the echo requests, the node is less vulnerable to attacks
than if it did accept them. This makes the ping utility useless when try-
ing to troubleshoot issues with the filtered interface and therefore may lead
to misleading diagnosis of problems in the network. Also keep in mind that
filtering these packets is only an annoyance for the Kers . . . they can still get to
the interface if they really want to.
The format of the ICMP echo request and reply packets are shown in
Figure 16-1.
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
Type Code Checksum
Identifier Sequence Number
Data
Figure 16-1 The ICMP echo reply/request datagram format
As mentioned already, the ICMP echo reply is returned for any ICMP echo
requests that are sent to the target node. The target node must respond to
echo requests when it can, and the reply will contain the data that was sent
to it from the originating node.
The echo request datagram type will be set to 8.12
The echo reply will have a datagram type set to 0.
The code field will be set to 0 for both the request and reply.
The Identifier and the Sequence number fields are used to
ensure that the proper reply is sent to the proper request.
The data field in the request and reply must contain the same data.
The ping command will also give you an idea of what the problem may be
when you are not able to get a valid response as shown in the example below.
The two error messages that you may receive when you are not able to reach
your target are:
Request timed out: There was no reply from the host.
Destination host unreachable: There is no route to the destination.
Does the clone() system call ultimately rely on fork functionality?
The critical difference is that fork creates a new address space, while clone optionally shares the address space between the parent and child, as well as file handles and so forth.
Actually, at the conceptual level, the Linux kernel doesn't know anything about processes or threads, it only knows about "tasks".
A Linux task can be a process, a thread or something in between. (Incidentally, this means that the strange children that vfork() creates fit perfectly well into the Linux "task" paradigm).
Now, tasks can share several things, see all the CLONE_* flags in the manpage for clone(2). (Not all these flags can be described as sharing, some specify more complex behaviours).
Or new tasks can choose to have their own copies of the respective resources. And since 2.6.16, they can do so after having been started, see unshare(2).
For instance, the only difference between a vfork() and a fork() call, is that vfork() has CLONE_VM and CLONE_VFORK set. CLONE_VM makes it share its parent's memory (the same way threads share memory), while CLONE_VFORK makes the parent block until the child releases its memory mappings (by calling execve() or _exit()).
Note that Linux is not the only OS to generalize processes and threads in this manner. Plan 9 has rfork().
fork()-->C_lib-->sys_fork()-->do_fork()
vfork()-->C_lib-->sys_vfork()-->do_fork()
clone()-->C_lib-->sys_clone()-->do_fork()
Actually, at the conceptual level, the Linux kernel doesn't know anything about processes or threads, it only knows about "tasks".
A Linux task can be a process, a thread or something in between. (Incidentally, this means that the strange children that vfork() creates fit perfectly well into the Linux "task" paradigm).
Now, tasks can share several things, see all the CLONE_* flags in the manpage for clone(2). (Not all these flags can be described as sharing, some specify more complex behaviours).
Or new tasks can choose to have their own copies of the respective resources. And since 2.6.16, they can do so after having been started, see unshare(2).
For instance, the only difference between a vfork() and a fork() call, is that vfork() has CLONE_VM and CLONE_VFORK set. CLONE_VM makes it share its parent's memory (the same way threads share memory), while CLONE_VFORK makes the parent block until the child releases its memory mappings (by calling execve() or _exit()).
Note that Linux is not the only OS to generalize processes and threads in this manner. Plan 9 has rfork().
fork()-->C_lib-->sys_fork()-->do_fork()
vfork()-->C_lib-->sys_vfork()-->do_fork()
clone()-->C_lib-->sys_clone()-->do_fork()
Subscribe to:
Comments (Atom)