http://site3.way2sms.com/jsp/LocateMobile.jsp
If I have eight hours for cutting wood, I spend six sharpening my axe.
Thursday, June 9, 2011
Thursday, March 24, 2011
Socket Programming - Part 1
Reference: http://www.tenouk.com/cnlinuxsockettutorials.html
Port Numbers
- 16 bit integers
- So a maximum port numbers are 2^16 = 65536 (0 to 65535)
- Unique with a machine/IP address
- Each service/application/daemon will have their own port number
- Required to make a connection (along with its host IP address)
Server & Client Port Numbers
- Connection is defined by: (Server IP and Port number) + (Client IP and port number)
- Server Port numbers are low numbers in the range 1 - 1023 (called as WELL KNOWN PORT NUMBER)
- Accessible only by Administrators (roots, in linux)
- Used for authentication
- A server running on a well-known port lets the OS know what port it wants to listen on
- Normally, client port numbers are higher number starting at 1024
- Client normally simples lets the OS picks a new port that is not already in use.
Monday, March 7, 2011
Background and Foreground Process
1. When you run a command (process), you can make it to run as a background process using $<cmd> &
2. If you forget to make that command as background, and if you feel you should do it now, then
- Press CTRL+Z (Suspend that process)
- $> bg disown 1 (make that process to be a background
3. Now if you want to check the list of background processes, type $> jobs
4. If you want to bring the background process to foreground, then type
$> fg %1
Again to make it a background process,
$> bg %1
2. If you forget to make that command as background, and if you feel you should do it now, then
- Press CTRL+Z (Suspend that process)
- $> bg disown 1 (make that process to be a background
3. Now if you want to check the list of background processes, type $> jobs
4. If you want to bring the background process to foreground, then type
$> fg %1
Again to make it a background process,
$> bg %1
Monday, February 7, 2011
Wednesday, August 25, 2010
Tuesday, August 24, 2010
Locks in Multi-processing/multi-thread programming
DeadLock:
A deadlock is a situation wherein two or more competing actions are each waiting for the other to finish, and thus neither ever does.
LiveLock:
A deadlock is a situation wherein two or more competing actions are each waiting for the other to finish, and thus neither ever does.
LiveLock:
A livelock is similar to a deadlock, except that the states of the processes involved in the livelock constantly change with regard to one another, none progressing. Livelock is a special case of resource starvation; the general definition only states that a specific process is not progressing.
A real-world example of livelock occurs when two people meet in a narrow corridor, and each tries to be polite by moving aside to let the other pass, but they end up swaying from side to side without making any progress because they both repeatedly move the same way at the same time.
Livelock is a risk with some algorithms that detect and recover from deadlock. If more than one process takes action, the deadlock detection algorithm can repeatedly trigger. This can be avoided by ensuring that only one process (chosen randomly or by priority) takes action.
new/delete operator
1. Return type of delete operator is void (not void*)
2. Exception and valid cases
char *p;
delete p; ==> exception (shown in picture)
Where as
char *p = 0;
delete p; .==> You can, however, use delete on a pointer with the value 0. This provision means that, when newreturns 0 on failure, deleting the result of a failed new operation is harmless.
2. Mixing both new/malloc and delete/free
class A {
public:
A() { cout << "Constructor" << endl;
~A() { cout << "Destructor" << endl;
};
int main() {
A *a = new A;
free(a); ==> Calls only constructor; not destructor
A *b = (A*)malloc(sizeof(A));
delete b; ==> Calls only destructor; not constructor
A *c = new A;
delete c; ==> Calls both constructor and destructor
}
2. Exception and valid cases
char *p;
delete p; ==> exception (shown in picture)
Where as
char *p = 0;
delete p; .==> You can, however, use delete on a pointer with the value 0. This provision means that, when newreturns 0 on failure, deleting the result of a failed new operation is harmless.
2. Mixing both new/malloc and delete/free
class A {
public:
A() { cout << "Constructor" << endl;
~A() { cout << "Destructor" << endl;
};
int main() {
A *a = new A;
free(a); ==> Calls only constructor; not destructor
A *b = (A*)malloc(sizeof(A));
delete b; ==> Calls only destructor; not constructor
A *c = new A;
delete c; ==> Calls both constructor and destructor
}
Monday, June 21, 2010
GDB unknown commands
All in gdb> prompt
1. Ctrl + p => To get the previous command
2. p array@sizeof(array) => To print all the array elements
3. set print pretty on => To print the structure elements' values in a neat way
4. p /x => prints the value in hexa decimal format
1. Ctrl + p => To get the previous command
2. p array@sizeof(array) => To print all the array elements
3. set print pretty on => To print the structure elements' values in a neat way
4. p /x
Tuesday, June 1, 2010
Subscribe to:
Posts (Atom)