Thursday, August 27, 2020

System Design Concepts

 

When any distributed system development  basic components needs to be consider are Scalability, Efficiency, Reliability, Manageability and Availability.

Scalability means system can be scaled in processing, network grow or memory capabilities increased or number of systems may increase as per demand.

Horizontal Scaling: Adding more systems/devices, it can be changed dynamically without reboot or interrupting current service.

Vertical Scaling: Adding more power like adding CPU's, RAM, Memory to existing system/devices, It may required to reboot or stop the service for upgrade time.



Sunday, June 28, 2020

Software development process

Waterfall model

   It will be used when there are clear requirements and fixed scope of a project.

   1. Collect & Analyze requirements
        clarify with stakeholders, detailed documented thoroughly
  2. Architecture definition
        - its blue print of a product.
        - which packages and components will form our system
       - what are fundamental types of each component
       - How the interaction with each component
       - is software secure, performance, error cases handled  and robust.
       - Is system design modular for future extension
       - Any third party components will be used, how is there licensing agreement.
  3. Impelementation
       - coding
       - unit testing
  4. Verification
       - All requirements implemented based on requirement agreement.
       - Functional testing
       - Performance validation
       - Security
       - User friendliness.
 5. Maintanence phase
       - Fixing customer bugs, enhancement etc.

 Agile Framework

It will be used when the requirement are unstable and may change frequently.
1. Scrum
2. Kanban
3. Test driven development(TDD) 

Thursday, June 25, 2020

gdb with release binary

debugging stripped binary by using disasamble the assmbly code

no symbols binary debig

Write below code into test.c
//----------------------------------
#include<stdio.h>

void fun(int x)
{
        int a = 10;
        printf("%d\n", a+x);
}
int main()
{
        int x = 5;
        fun(5);
        return 0;
}
//-----------------------------
-> compile with
#gcc -O3 test.c -o test

-> Look for a symbols using nm command
# nm test
0000000000201010 B __bss_start
0000000000201010 b completed.7698
                 w __cxa_finalize@@GLIBC_2.2.5
0000000000201000 D __data_start
0000000000201000 W data_start
00000000000005c0 t deregister_tm_clones
0000000000000650 t __do_global_dtors_aux
0000000000200dc0 t __do_global_dtors_aux_fini_array_entry
0000000000201008 D __dso_handle
0000000000200dc8 d _DYNAMIC
0000000000201010 D _edata
0000000000201018 B _end
0000000000000734 T _fini
0000000000000690 t frame_dummy
0000000000200db8 t __frame_dummy_init_array_entry
00000000000008a4 r __FRAME_END__
00000000000006a0 T fun
0000000000200fb8 d _GLOBAL_OFFSET_TABLE_
                 w __gmon_start__
0000000000000748 r __GNU_EH_FRAME_HDR
0000000000000510 T _init
0000000000200dc0 t __init_array_end
0000000000200db8 t __init_array_start
0000000000000740 R _IO_stdin_used
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
0000000000000730 T __libc_csu_fini
00000000000006c0 T __libc_csu_init
                 U __libc_start_main@@GLIBC_2.2.5
0000000000000560 T main
                 U __printf_chk@@GLIBC_2.3.4
0000000000000600 t register_tm_clones
0000000000000590 T _start
0000000000201010 D __TMC_END__


-> Remove symbols using strip -s
# strip -s test
-> Check for symbols
#nm test
nm: test: no symbols

-> run gdb for test
 #gdb test
GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from test...(no debugging symbols found)...done.
(gdb) b main
Function "main" not defined.

Lets start how to debug

-> Locate entry point with 'nfo file'
    (gdb) info file
Symbols from "/home/bkotha/tt/test".
Local exec file:
        `/home/bkotha/tt/test', file type elf64-x86-64.
        Entry point: 0x590
        ----
(gdb)

-> now set the break point at Entry point address
(gdb) b 0x590
   Breakpoint 1 (0x590)

-> then do the disasamble code
(gdb)disas


GDB

To debug a C or C++ application with gdb, built in debug mode i.e -g compiling option.
gdb commands 


-g in compilation: will enable debug symbols into binary.

Ex: gcc -g mytest.c  or gcc -g  test.c -o test
      g++ -g mytest.cpp or  g++ -g test.cpp -o test
1. start gdb with executable and set the break point and run  :
    #gdb test
    (gdb) b main # to set the break point at main function start
     (gdb) run  # program start executes 
2. start gdb without process and add process with 'file'.
     #gdb
     (gdb) file test # start the test executable for debugging 

3. Passing console arguments to process with run 
     (gdb) run  abc 3 # abc , 3 are command line arguments for test program.  

Back trace / stack frames : using bt
4. On break point / core parser gdb running out we can see current stack trace
       (gdb)bt
      It will list stack frames with frame id for each stack frame.
4.1  list each frame with f num
     (gdb) f 4 # here 4 is 4th stack frame listed in bt

Break Points: b , break, br any of this keywords can be used to set the break points
5.  Adding break point with filename with line number
     (gdb) b test.c:10  # break point at line number 10
6. Adding breakpoint with function names
      (gdb) break fun1   #fun1 is function in test.c
     (gdb) b myclass::fun2   #fun2 is myclass member function
6.1  break with memory address
       (gdb)b *(memoryAddress)  # debug symbol address instead variable or function.
7. List all break points
      (gdb) info break  # list all break points with break point numbers in sequence.
8. Delete/Remove breakpoint using d
      (gdb)d 3  #here 3 is the 3rd break point
9. traverse to next step or next break point &  step in  using n, c & s
      (gdb) s
      (gdb) n
      (gdb) c
10.  Print the values with p or print keyword
      (gdb) print iVar   #iVar is the variable
      (gdb) p fVal    #fVal is a variable
11. To set the values for variables using 'set'
       (gdb)set iVar=20
       (gdb)p iVar  # iVar will print 20
12. Execute the global functions after breakpoint hit
       (gdb)p myglobalFun  #myglobalFun is a global function can be run here
13. Listing the source code after some line number or function content  using 'list'
      (gdb)list 10
      (gdb)list myglobalFun
14.  Print the current debug code line numbers using 'frame'
      (gdb)frame
15. Quit from debug console qith q or quit key word
      (gdb)quit

x Command: ' x/FMT Address '
16. x command list the region of memory with specified address content in specified format.
     (gdb)x/100i $sp   # $sp is current stack pointer address, 100i - denotes the 100 address spaces code with disassemble code.
     (gdb)x/20s 0x435281720   # 20 lines code from address with code in string format
      (gdb)x/x  display in hexadecimal
      (gdb)x/d  display in decimal format
      (gdb)x/c display with charectors format
  help for x u can check in gdb
        (gdb) help x

Multithreading debug:
In multi threading  debugging mostly thread will share code, data segment from process space only thread specific it will be having stack content, so needs to debug only stack data.
17. To list the threads info using 'info threads'
     (gdb)info threads   # which will list all threads with thread id
18. To check all threads stack traces ' thread apply all bt '
      (gdb) thread apply all bt
19.  To check particular thread stack trace first set the treat using 'thread <tread id>' listed with 'info threads' the do bt for stack trace of that thread
      (gdb)thread 0x12463097   #0x12463097 thread id 
      (gdb) bt 


debug for release/ stripped / no symbols binary using gdb

20. With gdb will do 'info file', it lists Entry point address for program. set the break point at entry point address,  then do the 'disas' will list assembly code will be having main function address.

with assembly code try to under stand or match ur function names and data to under stand the flow.
more info click on link debug for release/ stripped / no symbols binary using gdb with more links in it



Thursday, May 14, 2020

interview question

Preparation practice and planning resource:
https://github.com/jwasham/coding-interview-university



1. How alexa project works basic flow to and from AWS cloud.
2. Sockte programming api's, what all api's are blocked calls. how multiple clients server will handle his point to know is select, but my knowledge that day is epoll.
3. Thread syntax, i asked for posix or c++11 threads.. he said any i went with c++11 which is easy i hope he was not happy as c++11 threads syntax is easy.
4. Pipes, named pipes, messageQueues what all differences and how each is advantage over other.
5. sip knowledge
6. asked package and expected..
---
1. About any project, i went with software updated with distribution in local network, alexa. by telling the problem statement of software update in customer place, handfree calling.
2. Explain about Smart pointers
3. Use of Virtual functions, pure virtual functions.
4. logical questions sum of numbers from 1 to 99  and one number missed how to ind the missed number, her expectation is (n*(n+1))/2.. then substract each element from it.remianing sum value is simmed number.
5. How to remove repeated sequence of charector example: abcbcdekeklmn -> abcdeklmn
6. Samsung SDAL layer project
-----------------------
1. When new project comes whats your approach as a architect.
2. Any tools used for derieving requirements finalizing.
3. Why still you are working as a developer?
4. When you need to outsource UI project what and all you will consider for client to deliver, how u will give ur requirement to him.
5. How you will give project health to management as a architect, as jirs task etc will be already will be provided by prgram manager status.
6. SOLID principles. : here his expactation is some keywords are usefull  like TDD etc.
7. How big is ur team, How is org structure.
8. Why you wil fit for this role?
-----------
1. Whats the projects, whats ur role in terms of technical.
2. Rate ur self is c, c++, linux, Go language, docker, DS.
3. If u given an DLL can you sort list with efficient approach.
4. swap 2 variables without using 3rd variable.
5. What all layers in OSI model.
6. What is difference between mac and ip address.
7. you have device other end device both end each is connected to switch, switch connected to router. as soon as device connection to device communication what all techincal aspects will happen?
8. Docker virtualization?
9. smart pointer
---------------
1. Piepline jenkins and classic jenkins ?
2. Difference between array and List in Python
3. How to specify one binary depends on other binary in makefile?
4. .Phony usage?
5. Dockers and containers?
6. Hardware speed speed is 50Mhz and Driver intrrupts came how you will calculate the uinturrupt handling time accurately.
7. you did git add, git commit for 10 files, from that before push command, one file should revert from commit what are the git steps with syntax?
8. what is the exact difference between git rabese and merge? syntax for each?
9.
----------------
1. You have 100MB allocated using new in heap, which is used by multiple threads and in one thread you need 50MB how you can assign from existing 100MB new pointer means he wanted how you will reallocate memoryin c++ using new?
2. What is the thrtead communication mechanism
3. How Qt is working with Android platform
4. 3liters, 5 liters jar to compute 4 liter puzzle
5. Thread lights finding which one without entering the room with switch ...
6. You have Cube of 4cm, and painted all the sides with green color, if i cut to 1cm cubes from it.. how many cubes will come without colors? how many 1cm cubes will come?
7. What is openembedded build framweork how it will work?
8. OOPS concepts
9. Ubutntu device partitions information how many partitions , how u will do partions commands for it. can we add more partitions?
10. some c++ code snippet to find out the problem
11. Mutex, threads and conditional way to control flow related
12. IPC
13. openGL related idea.
14. Why are u looking change?
-----------------
1. C++ oops concepts
2. EMpty class sze, how compiler memory structure for it if i create 20 objects?
3. polymorphism , compile time  and runtime? compile time how it will call corresponding in compiler level? any idea how compiler achieving compile time polymorphism?
4. Vtables and vptr with example classes to write.
5. if i have 10 base class pointers with 10 derieved classes are assigned having virtual in base. how many vtabled will get created?
6. virtual keyword for method, will be needed in derieved class method also ? if i keep what will h appen?
7. what is pure virtual ?
8. exeption handling related
9. What is the diffrence b/w expection handling and error handling?
10. WHat all design patterns used?
11. Multithreaded environment, singletern pattern code?
12. what tis future and  promise?
13. is multithreading is good or multiprocess is good why? How you will choose one over the other?
14. Socket programming simple usages?
15.
---------------
1. Understanding overall c++ skills with basic questions similar like oracle in telephonic
2. Wriiten test having code snioppet to find the issue and correct in given code having below issues
  - Dimond problem intensionally not placed virtual key board to resolve dimond problem.  
  - lock gaurd to use insteed mutex
  - order of locking, unlocking
  - private data  accsing after reinterpretaion cast
  - array outof bond issue
  - with the new allocated memory for array of objects but in delete not mentioningh braces for delete [].
  -
Below allproblems needs to write use case diagram, class diagram and code: and scalable, flexible, memory constraint devices...
3. Design a pattern and classes interface for Tweet like deleteTextTweet, deleteMultimediaTweet, readTextTweet, readMultimediaTweet, createTextTweet, createMultimediaTweet.
4. Have a UI page having id, name and address to be enter when same save page  should show that data and when cancel blank in that fields .. design his idea to write Qt code using MVC pattern...
5. What all solid principles, what is Dependency invserion principle needs to explain with code writing.
6. What all compilation stages for Qtapplications, expectation from is to specify moc for signals and slots
7. Hwo signals and slots implemented internally?
8. WHat all stages to use Qt in compiler ?
9. How to package Qt apk?
10. on screen images are playing with 50framesperseconds, bubbles are in screen when u click one one bubble that bubble get hilighted with + simbol on it.. design architecture.
11. from one hardware frmaes are commming continusly, ur process shoudl take the frmaes do some process on it and give it for display , no frameloss, stack memory is 128MB, each frame size is 4MB... design a system?
12. What Agile proces  and review process, CI/CD
13. INnovation
14. Design process for project execution
15. Hoq QT and android?
16 Why QT on android?
17. WHat all IPCS for where to use?
18. Design principles and patterns?
19. What are architectural processes and tools?
20.

1. How to transfer a sentence from one to other end over the noise wire
 "Bhaskar is a very good engineer"  ... Interviewer expectation is repeat the sentence with key words to reduce the bandwidth i.e in repeate Bhaskar good Enginner.

2. What is Lamda function how it will be usefull compare to normal function and its usage scenario?
3. Difference between RISC and CISC architecture?
4. uint val = 10; uint *ptr; ptr = &val;   What is the addressing mode of execution ?? Ans: Indirect addressing mode
5. What is sampling theorem have u implemented any in codec??
6. Any filter implementation and its use?
7. Who will invoke the scheduler? Interviewer looking for exact term from kernel
8. What is the Zombie process?
9. For multiplication or to find the number is even or not ? how u will write ?? Interviewer expectation to write using bitwise operator not binary operators.
10.coding practice questions like 1== a for comparision is  better or a == 1?
11.balanced tree is better or unbalanced tree is better? why?
12.How Memcpy will be implemented? if address overlapping occurs how u will handle.
14.How services will interact in android? why android will use binder even otherlinux ipc are present?
15.How service will work in android?
16.What are smart pointers?
17.How week pointer will be usefull
18.Wat is static assert?
19.What is dimond problem how it solved in c++?
20.Memory allocation methods and default value?  malloc, calloc, new, realloc???
21.With the micro controller IO ports how to generate the ramp wave??
22.What is the string and string builder in c++
23.

design pattern
c++,
c++11
role exact how may people

-------------------
thread pool
object cache implementation
LRU cache
Tree traversal in  order S
Guven an array  of numbers, and a number, find if array has sum of the given number (by adding 2 numbers)
string anagram
singleton
------------------------
- vector vs array
- vector -vs List
- linked list define structure
- Linked list intersected with other linked list
- print BST left view

- auto, lamda syntax
- projects
- design pattern
- how t0 analyze core dump
- most dificult roblem solved
-
- linux os internels IPC
- linux crash debugging
- n/w protocol

---- given an array of x, y cordinates,find the nearest, loangest cordinates from the origin 0,0 ? l = sqrt(x2+y2) sort all of them
- thread pooling like number of reuqtest are more and queue is lesser size...
- linked list reverse
- print event , odd
- challenging problem
- c++, system experience

-----
-What is little endian/big endian?
-Generic projects details
- when to use shared memory
-why pipe not used in server media received to process same media can be given to process.
- multi process vs multi thread difference.
---
- program to align 0's to left and 1's to right in bool array.
- unique pointer usage and write a program to demonstrate
- change unique pointer code to smart pointer and how it wil behave.
-what are multithreading, how to control, protect data.
- what are all IPC and and how it works
- what is lamda function how to use them.
- stl'd details.

---
- What are socket apis
- Difference b/w udp, tcp
- voip, sip is in which layer protocol
- What all details in sock file descriptor
- what is select and how its use full
- generic multithreading details
- how cloud comm happens what all protocls used to communicate.
----

- reverse string
-c++11 concepts like smart pointers, lamda, auto, stl's
-sub string finding
- convert java code to c code having interface class and derived classed A, B.. object of A, B will be there, so here main intension of writing struct and function pointer in struct members.
- nibble swap in a byte.
- c language reference variable effect in called to callee

--
- write a code having copy constructor, operator constructor, destructor and class having pointer data members.
- Stack implementation using templates, but stack not limit capacity it should grow like how much we use.
- c++ 11 concepts.
-ipc concepts in details.



Thursday, April 30, 2020

Generic

Cache :
Caching is a process of storing the frequently - accessed data temporarily in a cache so we can re use in next time request.

Monday, January 27, 2020

OOPS

OOPS concepts----------------------------------------------------------------------------
OOP programming  runs around below keywords.
Object oriented programming used to simulate real life things into your code is called as OOP.

OOPS 2 entities:
Class:(blue print of object) is a specification of object
       It is having name, properties and methods.
Ex: College student details: attributes/data members and functions and method.
Object: (instance of a class) is a peace of code which represent the real life entity.
      Object will be having its own identity,  properties and behavior.
Ex: the black[property] dog[object] barks[behavior]
Ex: TennisCourt:  here court is object Court has attributes like color, surface, dimensions etc called variables/data members, and functionality like court booking, court cleaning etc called functions/methods.
Change in attributes will change the behavior of members object.

OOPs 4 Principles:
  • Encapsulation: Encapsulation is the mechanism of binding the data and methods together and hiding it from the outside world. Encapsulation is achieved by keeping its state private(access specifiers) so that other objects don’t have direct access to its state. Instead, they can access this state only through a set of public methods. Ex: Capsul tablet which is encapsulated with medicine and chemicals. 
  • Abstraction: Abstraction will help by hiding internal implementation details of objects and only exposes the operations that are relevant to objects. Ex: Student can have multiple attributes but we take which are relevant for college i.e name , age and rool number, as college no need to know his girl friends names, his child hood school friends etc i.e means only relevant for that business.
  • Inheritance: Inheritance is the mechanism of creating new classes from existing ones. Which help in reusability. It works on relationship. One object aquires the properties of other object.
  • Polymorphism: Polymorphism (from Greek, meaning “many forms”) is the ability of an object to take different forms and thus, depending upon the context, to respond to the same message in different ways. Take the example of a chess game; a chess piece can take many forms, like bishop, castle, or knight and all these pieces will respond differently to the ‘move’ message.
Design-----------------------------------
Design always should follow 3 things
DRY- Donot repeat yourself
Divide and Conquer - Code keep on adds in a file its difficult to change
Expect Change - Always new features should come which requires the change.

SOLID:
S - Single responsible principle : Class should have only one reason to change, it can change multiple times but it should change for only with its context of cricket.
Ex: Sachin performance only  vary because of sporting reasons not because of BCCI president changed, or Needs to do act in add i.e this things should not be the reasons to change.

O - Open for extension and closed for modification : Create interface and add concrete classes for each type of base interface. Ex; IPayment  having makePayment() function and all sub classes like CardPayment , Cash payment, should have makepayment method so tomorrow if online payment comes without changing existing concrete classes we will add OnlinePayment class with make paymethod where u need use name password for login and then pay.

L- Liskov's substitution principle: Child class should able to substitute the base class functionality.
Example; Don and his 3 sons , one son is not his actual son his neighbor son who is a cook, then he will not replace which  his father dead, instead of killing enemies he will serve tea, copy etc.

I- Interface Segregation Principle : Do not force any client class should not implement interface which is irrelevant for it.

D- Dependency inversion principle: Responsibility of creation of dependency object should outsource to the consuming class.

Practices-----------------------------------------------------------------------
OO Analysis and Design means: Identifying the objects for the problem, and relation between the objects and providing the interface for each object.
1. Collect the requirement
Write all the requirement with pen and paper/white board or use tools/ system.

   - functional requirement: what is the needed the application look, work what all boundaries.
   Non func. requirement:
     - performance requirement
     - Security requirement : data access etc
     - documentation, support
 Map the requirements to technical description.
    Use cases:
          - title:  short description of use cases,
          - actor : user how he interact with use cases (who all involved, like system admin class, person class, data base etc.)
          - scenario: how the scenario works.
   
2. Describe the system in brief  or write the wire frames.
3. Identify the classes
4. create the uml diagrams[sequence, use case, etc] 
UML:(Unified modeling language) :
    Graphical notation to easily can be conveyed the business/ software system.

Many diagram types:class diagram, Object diagram, use case diagram, activity diagram, sequence diagram and state/communication/interaction diagram.
Association, multiplicity, aggregation, composition, Generalization, Dependency and abstract class.
use case diagram: Oval on center of diagram with use case name in oval,  include  and  extend string.
class diagram: has a rectangle with 3 horizontal section upper section shows the class name, middle section shows properties/ variables/data of class and lower section contains method/function names called class operations. 
Sequence diagram: across the top of your diagram, identify the class instances(object) by putting each class inside a box. 

Tuesday, January 21, 2020

Design Patterns

Pattern are for Flexible, Maintainable and extendable, i.e Add new features, replace feature and remove feature should not be complex.


Creational: Object Instantiation
Structural : Class relationship and Hierarchical
Behavioral:  Objects intercommunication

Creational:
Factory Method:
Provides an interface to create an object but defers the creation to the sub class.
- Creates an object base don run time parameter
- Do not need to know which objects you will needed to create.

Port forwarding issues and port collusion by more then one process

Port forwarding script to identify collusions  Identifying local and remote port forwarding processes, as well as checking for potential col...