Archive for November, 2008
How to find who is currently logged on what they are doing
Nov 8th
The “w” command can be used to find the users who are currently logged in to the machine and find the processes they are running at the moment. The first line is similar to what the command uptime prints and it displays system up time and load averages. For each logged in user, it also displays information like how long they have been idle and where from they have logged in to the system. For example in the following example, the user neo (which is me) is logged in from a host with IP address 192.168.30.10.
[neo@techpulp ~]$ w 10:44:03 up 46 More >
What is the command to see how long the system is up
Nov 7th
The UNIX command uptime can be used to determine how long the system is up since last reboot. This command displays one line information containing the current time, how long system has been running, how many users are currently logged on and the system load averages for the past 1, 5, and 15 minutes.
[neo@techpulp ~]# uptime 17:54:01 up 4 days, 7:57, 7 users, load average: 0.19, 0.22, 0.18 [neo@techpulp ~]#
How to get system uptime in C
Nov 7th
The sysinfo system call can be used to retrieve current system up-time. The function get_uptime() in the following code snippet returns system uptime in seconds.
[neo@techpulp ~]$ cat uptime.c
#include <stdio.h>
#include <sys/sysinfo.h>
long get_uptime(void)
{
struct sysinfo sinfo;
sysinfo(&sinfo);
return (sinfo.uptime);
}
int main(int argc, char *argv[])
{
printf("System is up for %ld seconds\n", get_uptime());
return 0;
}
The following shows the ouput of the above C example program.
[neo@techpulp ~]# gcc uptime.c -o uptime [neo@techpulp ~]# ./uptime System is up for 374080 seconds [neo@techpulp ~]# [neo@techpulp ~]# ./uptime System is up for 374085 seconds [neo@techpulp ~]#
More >
How to see help of internal command of CVS
Nov 7th
The –help option followed by CVS internal commands like checkout, checkin, tag etc can be used to get the help for a specific command. The following example shows how to see help for tag command.
[neo@techpulp ~]# cvs --help tag
Usage: cvs tag [-bcdFflR] [-r rev|-D date] tag [files...]
-b Make the tag a "branch" tag, allowing concurrent development.
-B Allows -F and -d to disturb branch tags. Use with extreme care.
-c Check that working files are unmodified.
-d Delete the given tag.
-F Move tag if it already exists.
-f Force a head revision match if tag/date not found.
-l Local More > How to create a CVS branch
Nov 7th
A branch tag is very much different from a normal tag. A normal tag can be just used to tag a particular version of sources and retrieve the exact version later. No independent development can happen based on a normal tag. However a branch tag creates a virtual branch in CVS repository sources and facilitates parallel development to happen on that branch. There is no limit on number of branches.
For example, if you plan to work on two releases of same project, you would want to create a branch for each release and work on them separately.
The creation of a More >
How to move a CVS tag
Nov 7th
Moving an existing tag is needed if some files are forgotten to be checked in before tagging the sources. In such cases, the remaining files can be checked in and then tag the sources with -F option.
CVS doesn’t allow duplicate tags to be present in the repository. You can either chose a different tag name or chose to move the existing tag if same tag name has to be used. However this is applicable for normal tags and not for branch tags. The following example tags the sources with a tag called my-release-tag-1. This moves the tag to latest sources if More >
How to remove a CVS tag
Nov 7th
An existing CVS tag can be removed by using -d option with cvs tag command. However a branch tag can’t be remove from the CVS repository. The following example removes a tag called my-release-tag-1.
[neo@techpulp ~]# cvs tag -d my-release-tag-1 [neo@techpulp ~]#
How to extract IP address from a string in C
Nov 5th
The library function inet_aton can be used to extract IP address from a string format (eg: “123.23.42.76″). This function returns non-zero value if the IP address is valid and zero if it is an invalid IP address. The following example shows how to use this library function.
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
char *ips[] = {
"12.34.56.7",
"123.123.123.123",
"255.255.255.255",
"345.123.23.54",
NULL
};
int main(int argc, char *argv[])
{
int i;
struct in_addr ia;
i = 0;
while(ips[i]) {
if(inet_aton(ips[i],&ia) == 0) {
printf("%s is an INVALID ip address\n", ips[i]);
} else {
printf("%s is a VALID ip address. 0x%lx\n", More > How to uninstall an RPM
Nov 4th
The rpm -e command can be used to erase an installed RPM. The following example attempts to delete a RPM called codeina-0.10.1-5.fc8 .
[neo@techpulp ~]# rpm -e codeina-0.10.1-5.fc8 [neo@techpulp ~]#
If the RPM given is not an installed RPM, it shows an error message as shown below.
[neo@techpulp ~]# rpm -e abcd error: package abcd is not installed [neo@techpulp ~]#
How to find list of installed files of an RPM
Nov 4th
The rpm -q -l can be used to get the list of files installed by an installed RPM. The following example finds the files installed by bash RPM.
[neo@techpulp ~]# rpm -aq | grep bash bash-3.2-18.fc8 [neo@techpulp ~]# rpm -q -l bash-3.2-18.fc8 /bin/bash /bin/sh /etc/skel/.bash_logout /etc/skel/.bash_profile /etc/skel/.bashrc /usr/bin/bashbug-32 /usr/share/doc/bash-3.2 /usr/share/doc/bash-3.2/CHANGES .... /usr/share/man/man1/unset.1.gz /usr/share/man/man1/wait.1.gz [neo@techpulp ~]#


Recent Comments