dd . one device to another

commandline session

$ 4.2.20 2 84---> dd if=/dev/pts of=stdout
dd: reading `/dev/pts': Is a directory
0+0 records in
0+0 records out
0 bytes (0 B) copied, 0.001431 s, 0.0 kB/s
$ 4.2.20 3 85---> dd if=/dev/sda
sda   sda1  sda2  sda5
$ 4.2.20 3 85---> dd if=/dev/sda1 of=/dev/sda
sda   sda1  sda2  sda5
$ 4.2.20 3 85---> dd if=/dev/sda1 of=/dev/sda
sda   sda1  sda2  sda5
$ 4.2.20 3 85---> dd if=/dev/sda1 of=/dev/sdb
dd: opening `/dev/sda1': Permission denied
$ 4.2.20 4 86---> sudo dd if=/dev/sda1 of=/dev/sdb
[sudo] password for jeffrin:
^C1416945+0 records in
1416944+0 records out
725475328 bytes (725 MB) copied, 18.526 s, 39.2 MB/s
$ 4.2.20 5 87--->

dpkg commandline

commandline session

$ 4.2.20 7 25---> dpkg --status cam
Package `cam' is not installed and no info is available.
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.
$ 4.2.20 8 26---> dpkg --status ftp
Package: ftp
Status: install ok installed
Priority: standard
Section: net
Installed-Size: 132
Maintainer: Alberto Gonzalez Iniesta 
Architecture: amd64
Source: netkit-ftp
Version: 0.17-25
Replaces: netstd
Depends: libc6 (>= 2.3), libncurses5 (>= 5.5-5~), libreadline6 (>= 6.0), netbase
Description: classical file transfer client
 This is the user interface to the ARPANET standard File Transfer Protocol.
 The program allows a user to transfer files to and from a remote network
 site.
$ 4.2.20 9 27--->


$ 4.2.20 25 43---> dpkg --list | cut -c 1-40 | tail -n 10
ii  yelp-xsl
ii  youtube-dl
ii  zeitgeist-core
ii  zenity
ii  zenity-common
ii  zgv
ii  zip
ii  zlib1g
ii  zlib1g-dev
ii  zsh
$ 4.2.20 26 44--->

exit

commandline session

$echo $SHELL
/bin/bash
$ksh
$echo $SHELL
/bin/bash
$echo $shell

$csh
% echo $SHELL
/bin/bash
% exit
% exit
$exit
$ksh
$ps
  PID TTY          TIME CMD
 3523 pts/1    00:00:00 bash
 3573 pts/1    00:00:00 ksh
 3574 pts/1    00:00:00 ps
$csh
% ps
  PID TTY          TIME CMD
 3523 pts/1    00:00:00 bash
 3573 pts/1    00:00:00 ksh
 3575 pts/1    00:00:00 csh
 3576 pts/1    00:00:00 ps
% exit
% exit
$ps
  PID TTY          TIME CMD
 3523 pts/1    00:00:00 bash
 3573 pts/1    00:00:00 ksh
 3577 pts/1    00:00:00 ps
$exit
$ps
  PID TTY          TIME CMD
 3523 pts/1    00:00:00 bash
 3578 pts/1    00:00:00 ps
$

df and free

commandline session

$df
Filesystem                                             1K-blocks      Used Available Use% Mounted on
rootfs                                                 234611560 217250928   5443016  98% /
udev                                                      991480         0    991480   0% /dev
tmpfs                                                     199568       604    198964   1% /run
/dev/disk/by-uuid/26cca090-8a72-4443-859f-7a67b7188357 234611560 217250928   5443016  98% /
tmpfs                                                       5120         0      5120   0% /run/lock
tmpfs                                                     399132        72    399060   1% /tmp
tmpfs                                                     399132       700    398432   1% /run/shm
$df -h
Filesystem                                              Size  Used Avail Use% Mounted on
rootfs                                                  224G  208G  5.2G  98% /
udev                                                    969M     0  969M   0% /dev
tmpfs                                                   195M  604K  195M   1% /run
/dev/disk/by-uuid/26cca090-8a72-4443-859f-7a67b7188357  224G  208G  5.2G  98% /
tmpfs                                                   5.0M     0  5.0M   0% /run/lock
tmpfs                                                   390M   72K  390M   1% /tmp
tmpfs                                                   390M  692K  390M   1% /run/shm
$free
             total       used       free     shared    buffers     cached
Mem:       19951006    1885120     110536          0      68056     840720
-/+ buffers/cache:     976344    1019312
Swap:      5843964        132    5843832
$free -m
             total       used       free     shared    buffers     cached
Mem:          1948       1842        106          0         66        821
-/+ buffers/cache:        954        994
Swap:         5706          0       5706
$

date and cal

commandline session

$date
Sat Apr  7 19:34:47 IST 2012
$date -R
Sat, 07 Apr 2012 19:34:51 +0530
$date -u
Sat Apr  7 14:05:05 UTC 2012
$cal
     April 2012
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

$cal -h
     April 2012
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

$cal -e
Usage: cal [general options] [-hjy] [[month] year]
       cal [general options] [-hj] [-m month] [year]
       ncal [general options] [-bhJjpwySM] [-s country_code] [[month] year]
       ncal [general options] [-bhJeoSM] [year]
General options: [-NC31] [-A months] [-B months]
For debug the highlighting: [-H yyyy-mm-dd] [-d yyyy-mm]
$

arch and uname

commandline session

$arch
i686
$uname -m
i686
$arch --help
Usage: arch [OPTION]...
Print machine architecture.

      --help     display this help and exit
      --version  output version information and exit

Report arch bugs to bug-coreutils@gnu.org
GNU coreutils home page: 
General help using GNU software: 
For complete documentation, run: info coreutils 'arch invocation'
$

search algorithm for GNU source installer

/* Search API Algorithm  Copyright (c) 2012 Jeffrin Jose


 This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
     (at your option) any later version.

 This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
     along with this program (look for the file called COPYING);
     if not, write to the Free Software Foundation, Inc.,
         51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

     You can contact the author (Jeffrin Jose) by sending a mail
     to jeffrin@rocketmail.com
*/

#include<stdio.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<pwd.h>
#include<unistd.h>
#include<string.h>
#include<errno.h>
#include<dirent.h>
#include<stdbool.h>


int main(int argc, char *argv[]) {
int i =0;
char *p;
FILE *sfile;
char buffer[200];
char *sword = "htop"; /* word to search */
bool found = false;
struct passwd *pw = getpwuid(getuid());

char *homedir = pw->pw_dir;
const char *plocation = "/.sourceinstall/packages";
/* printf("%sn",homedir); */
const char *npath = strcat(homedir,plocation);
int value = chdir(npath);
DIR *opendirp = opendir(npath);
struct dirent *d;
while ((d = readdir(opendirp)) != NULL )
/* for (i=0;id_name,"r");
while (!found && (fgets(buffer, sizeof(buffer), sfile ) != 0))
{
found = strstr(buffer,sword);
}
/* printf("%dn",found); */
if (found == 1)
printf("found in: %sn",d->d_name);
fclose(sfile);

/* printf("%d %dn",value,errno); */
/* printf("%sn",d->d_name); */
}
closedir(opendirp);

return 0;
}

maps Memory maps to executables and library files

UNIX Parameter

$sudo cat /proc/1/maps
[sudo] password for jeffrin:
00400000-00409000 r-xp 00000000 08:01 6070276                            /sbin/init
00608000-00609000 r--p 00008000 08:01 6070276                            /sbin/init
00609000-0060a000 rw-p 00009000 08:01 6070276                            /sbin/init
01c21000-01c42000 rw-p 00000000 00:00 0                                  [heap]
7f641ff63000-7f641ff100000 r-xp 00000000 08:01 14532647                   /lib/x86_64-linux-gnu/libdl-2.13.so
7f641ff100000-7f64201100000 ---p 00002000 08:01 14532647                   /lib/x86_64-linux-gnu/libdl-2.13.so
7f64201100000-7f6420166000 r--p 00002000 08:01 14532647                   /lib/x86_64-linux-gnu/libdl-2.13.so
7f6420166000-7f6420167000 rw-p 00003000 08:01 14532647                   /lib/x86_64-linux-gnu/libdl-2.13.so
7f6420167000-7f64202e4000 r-xp 00000000 08:01 14532633                   /lib/x86_64-linux-gnu/libc-2.13.so
7f64202e4000-7f64204e4000 ---p 0017d000 08:01 14532633                   /lib/x86_64-linux-gnu/libc-2.13.so
7f64204e4000-7f64204e8000 r--p 0017d000 08:01 14532633                   /lib/x86_64-linux-gnu/libc-2.13.so
7f64204e8000-7f64204e9000 rw-p 00181000 08:01 14532633                   /lib/x86_64-linux-gnu/libc-2.13.so
7f64204e9000-7f64204ee000 rw-p 00000000 00:00 0
7f64204ee000-7f642050b000 r-xp 00000000 08:01 95764100                    /lib/x86_64-linux-gnu/libselinux.so.1
7f642050b000-7f642070b000 ---p 0001d000 08:01 95764100                    /lib/x86_64-linux-gnu/libselinux.so.1
7f642070b000-7f642070c000 r--p 0001d000 08:01 95764100                    /lib/x86_64-linux-gnu/libselinux.so.1
7f642070c000-7f642070d000 rw-p 0001e000 08:01 95764100                    /lib/x86_64-linux-gnu/libselinux.so.1
7f642070d000-7f642070e000 rw-p 00000000 00:00 0
7f642070e000-7f642074c000 r-xp 00000000 08:01 14401899                   /lib/x86_64-linux-gnu/libsepol.so.1
7f642074c000-7f642094c000 ---p 0003e000 08:01 14401899                   /lib/x86_64-linux-gnu/libsepol.so.1
7f642094c000-7f642094d000 rw-p 0003e000 08:01 14401899                   /lib/x86_64-linux-gnu/libsepol.so.1
7f642094d000-7f642096c000 r-xp 00000000 08:01 14532660                   /lib/x86_64-linux-gnu/ld-2.13.so
7f6420b44000-7f6420b48000 rw-p 00000000 00:00 0
7f6420b6a000-7f6420b6c000 rw-p 00000000 00:00 0
7f6420b6c000-7f6420b6d000 r--p 0001f000 08:01 14532660                   /lib/x86_64-linux-gnu/ld-2.13.so
7f6420b6d000-7f6420b6e000 rw-p 00020000 08:01 14532660                   /lib/x86_64-linux-gnu/ld-2.13.so
7f6420b6e000-7f6420b6f000 rw-p 00000000 00:00 0
7fffa543c000-7fffa545d000 rw-p 00000000 00:00 0                          [stack]
7fffa55ff000-7fffa5600000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]

Parameter Definition

The /proc/PID/maps file containing the currently mapped memory regions and
their access permissions.


where "address" is the address space in the process that it occupies, "perms"
is a set of permissions:

 r = read
 w = write
 x = execute
 s = shared
 p = private (copy on write)

"offset" is the offset into the mapping, "dev" is the device (major:minor), and
"inode" is the inode  on that device.  0 indicates that  no inode is associated
with the memory region, as the case would be with BSS (uninitialized data).
The "pathname" shows the name associated file for this mapping.  If the mapping
is not associated with a file:

 [heap]                   = the heap of the program
 [stack]                  = the stack of the main process
 [vdso]                   = the "virtual dynamic shared object",
                            the kernel system call handler

 or if empty, the mapping is anonymous.


Parameter Code Related Internals

struct proc_dir_entry *my_proc_file = NULL;
 /* Create a proc file */
my_proc_file = create_proc_entry("rt-embedded", S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH, NULL);

if (my_proc_file)
{
  /* Setup the Read and Write functions */
  my_proc_file->read_proc  = my_proc_read;
  my_proc_file->write_proc = my_proc_write;
}

Related From a Paper

The full address space of a process is rarely used, only sparse regions are. Each
region is represented by a vm_area_struct which never overlap and represent a set
of addresses with the same protection and purpose. Examples of a region include
a read-only shared library loaded into the address space or the process heap. A
full list of mapped regions a process has may be viewed via the proc interface at
/proc/PID/maps where PID is the process ID of the process that is to be examined.
The region may have a number of di?erent structures associated with it as illus-
trated in Figure 5.2. At the top, there is the vm_area_struct which on its own is
enough to represent anonymous memory.
If a ?le is memory mapped, the struct ?le is available through the vm_file ?eld
which has a pointer to the struct inode. The inode is used to get the struct
address_space which has all the private information about the ?le including a set
of pointers to ?lesystem functions which perform the ?lesystem speci?c operations
such as reading and writing pages to disk

source :
Understanding The
Linux Virtual Memory Manager
Mel Gorman
15th February 2004

http://www.cs.miami.edu/~burt/learning/Csc521.071/notes/understand.pdf

Theory Drop

In  computer  science, a  heap  is  a  specialized tree-based  data
structure that satisfies the heap property
Heaps

A binary tree has the heap property iff
it is empty or
the key in the root is larger than that in either child and both subtrees have the heap property.

source:http://en.wikipedia.org/wiki/Heap_(data_structure)
http://www.cs.auckland.ac.nz/~jmor159/PLDS210/heaps.html

Fix Required

Related from Paper section has junk charecters
which should be replaced by proper letters.