Posts Tagged ‘unix command’

Shared memory and Semaphores are types of IPC. IPC stands for Inter Process Communication. There are couple more IPCs, namely Pipes & Message Queue. I am not going to go deep into the details of these IPCs because its not in the context here. Lets directly go to the commands under discussion:

ipcs: To display the shared memory and semaphores.

Example: ipcs command with -a option lists all the IPC facilities which can be read by the current process. It provides details about message queue, semaphore and shared memory.

# ipcs -a

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0xc616cc44 1056800768 oracle    660        4096       0
0x0103f577 323158020  root      664        966        1
0x0000270f 325713925  root      666        1          2

------ Semaphore Arrays --------
key        semid      owner      perms      nsems
0x0103eefd 0          root      664        1
0x0103eefe 32769      root      664        1
0x4b0d4514 1094844418 oracle    660        204

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages
0x000005a4 32768      root       644        0            0

Command to list all Message Queues, -q.

$ ipcs -q

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages
0x000005a4 32768      root       644        0            0

(more…)

I have a friend who keeps bugging me for small small scripting solutions, and every time I enjoy helping him just because all those times I learn new things in Unix. But I never thought of capturing these things anywhere. Then I thought of putting them in my own blog, here! 🙂

Coming to the recent question he asked me, he wanted to capture the common entries in two files.
Say, file1 contains following entries:
AT010
AT013
AT015

And file2 contains:
AT011
AT012
AT013
AT014
AT015

How do I find the common lines? Simple, use comm command.
$ comm -12 file1 file2
AT013
AT015

Smooth, isn’t it? 🙂
But what if the files are not sorted? Then comm can’t help you alone, you need to take help of another command sort.

Consider the above files are not sorted, then:
$ sort file1 > new_file1
$ sort file2 > new_file2
$ comm -12 new_file1 new_file2

would give the same result as above.

(more…)