Unix domain socket

Refer to http://en.wikipedia.org/wiki/Unix_domain_socket (For personal research)

A Unix domain socket or IPC socket (inter-process communication socket) is a data communications endpoint for exchanging data between processes executing within the same host operating system. While similar in functionality to named pipes, Unix domain sockets may be created as byte streams or as datagram sequences, while pipes are byte streams only. Processes using Unix domain sockets do not need to share a common ancestry. The programmer’s application interface (API) for Unix domain sockets is similar to that of an Internet socket, but does not use an underlying network protocol for communication. The Unix domain socket facility is a standard component of POSIX operating systems.

Unix domain sockets use the file system as address name space. They are referenced by processes as inodes in the file system. This allows two processes to open the same socket in order to communicate. However, communication occurs entirely within the operating system kernel.

In addition to sending data, processes may send file descriptors across a Unix domain socket connection using the sendmsg() and recvmsg() system calls.

Extra: unix domain sockets guide

ldd on Mac OS X

I was used to use ldd on Linux and Solaris to print out the dynamic library linkage.

However, there is no ldd on Mac OS X but a equivalent tool called otool.

Here is the usage:

Usage: otool [-fahlLDtdorSTMRIHvVcXm] <object file> ...
	-f print the fat headers
	-a print the archive header
	-h print the mach header
	-l print the load commands
	-L print shared libraries used
	-D print shared library id name
	-t print the text section (disassemble with -v)
	-p <routine name>  start dissassemble from routine name
	-s <segname> <sectname> print contents of section
	-d print the data section
	-o print the Objective-C segment
	-r print the relocation entries
	-S print the table of contents of a library
	-T print the table of contents of a dynamic shared library
	-M print the module table of a dynamic shared library
	-R print the reference table of a dynamic shared library
	-I print the indirect symbol table
	-H print the two-level hints table
	-v print verbosely (symbolically) when possible
	-V print disassembled operands symbolically
	-c print argument strings of a core file
	-X print no leading addresses or headers
	-m don't use archive(member) syntax
	-B force Thumb disassembly (ARM objects only)

 

To use it like ldd, just type

otool -L executable

For example:

$ otool -L a.out
a.out:
	/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.0.0)

unsigned long DOES NOT work on SOLARIS

When I doing an assignment of mine, I found the output of my Mac and school Solaris system is different which should be the same.

After a series of testing, I found that unsigned long does not work on solaris. It works same as unsigned int.

Look at the C code here:

/* Author Name: Need-Being
   Modification Date: 17/08/11
   File Description: Test unsigned int and unsigned long */

int main()
{
        unsigned int a = 0;
        unsigned long b;

        a = ~a; /* Make it maximun of unsigned int */
        b = a;
        b += 1;

        printf("%u\t%lu\t%s\n", a , b, (a < b)?"Works":"Does not work");
        printf("%d\t%d\n", sizeof(unsigned int), sizeof(unsigned long));

        return 0;
}

The output should be “4294967295 4294967296 Works” and “4 8”.

However, the actual output is

$ a.out
4294967295 0 Does not work
4 4

The unsigned long behaves the same as unsigned int.

Test is processed on a sparc machine in my faculty:

$ uname -a
SunOS banshee 5.10 Generic_144488-17 sun4u sparc SUNW,Sun-Fire-V240