Sunday, December 29, 2019

Free up disk space on Mac

Have you ever run out to disk space in your mac? You might need to figure out which files and folders eat most of your disc space.

Option 1: Finding the largest Files
One option is to open the Finder and search the files using 'This Mac' and sort the files by size.


Option 2: Finding the largest Folders
Open the terminal and go to your user folder by typing 'cd ~/' then enter the following command. It will list the largest folders in the sorting order. It may take a while to list. Don't worry about the warning messages.

du -a * | sort -r -n | head -10

Then you can proceed to delete the unnecessary folders

One of the culprits of eating disk space is the XCode app and its related files


Friday, December 27, 2019

Software Security Summary


Image result for software security

the goal of software security is to maintain the confidentiality, integrity, and availability of information resources in order to enable successful business operations. This goal is accomplished through the implementation of security controls.

Risk is a combination of factors that threaten the success of the business. This can be described conceptually as follows: a threat agent interacts with a system, which may have a vulnerability that can be exploited in order to cause an impact.

Eg: a car burglar (threat agent) goes through a parking lot checking cars (the system) for unlocked doors (the vulnerability) and when they find one, they open the door (the exploit) and take whatever is inside (the impact).

A dev team: Approaches the system based on the intended functionalities
An attacker: What operations can be done on the system(nothing avoided is possible)

security holes can be introduced in

  1. Requirement gaps
  2. System logic error
  3. Poor coding practices
  4. Improper deployments
  5. Security holes introduced during maintenance and updating phases
Reference: https://www.owasp.org/images/0/08/OWASP_SCP_Quick_Reference_Guide_v2.pdf


Thursday, December 12, 2019

Threads Vs Processes


You might come across situations where you need to decide whether to use a thread or a process to achieve a certain task. Here I am sharing my experience on selecting what's best depending on your requirements

First, let's what is a process?
  • A process is an executing instance of an application/program
  • Process control block holds information about the process.
  • Process priority, process id, process state, CPU register, program counter, stack pointer, the status of opened files, scheduling algorithms, etc. 
  • A process can create other processes which are known as Child Processes.
  • The process takes more time to terminate and it is isolated means it does not share the memory with any other process.

Then what is a thread?
  • A thread is a path of execution within a process. 
  • A process can contain multiple threads
  • A thread takes less time to terminate as compared to a process
Let's see how does a process work
  • Process creation using fork system call
    • fork() creates a replica of the parent process 
    • Page Table and Kernal Stack are duplicated, new PCB is created
    • Child process state is set to NEW -> READY
    • Process is moved to the ready queue of the Kernal
    • Copy On Write (COW) is used by the child process
  • The first process of Unix system is known as the Super parent.
    • Location: /sbin/init
    • Created by the kernel during boot
    • Typically starts several scripts present in /etc/init.d
  • Process termination
    • Voluntary termination: exit(0)
    • Involuntary termination: kill(pid, signal) 
    • Pid: process Id
    • Signal: asynchronous message send by the OS/another process (eg: SIGTERM, SIGQUIT)
  • Process communication(IPC)
    • Shared memory: shmget, shmat, shmdt 
    • Message passing:
    • Shared memory is created in kernel
    • Slow
    • Pipes
    • Signals
How does a thread work?
  • Threads are very inexpensive to create and destroy, and they are inexpensive to represent
  • When a new thread is created it shares its code section, data section and operating system resources like open files with other threads.
  • But it allocates its own stack, register set and a program counter.
  • With so little context, it is much faster to switch between threads
  • Creating a thread, switching between threads and synchronization between threads can all be done without the intervention of the kernel

Processes are good when you have a task, where the task

  • Has sufficient work to do for a long period of time continuously
  • Does not require much communication between tasks
  • Has less context switching
  • Can independently work from other tasks
  • Does not require to be controlled

Threads are good when you have a task, where the task

  • Has less heavy work to do
  • Has a small life span
  • Requires communication between other tasks
  • Requires context switching
  • Depends on other tasks
  • Requires synchronization
  • Depends on shared data/resources
  • Requires control and coordination

You may consider the following factors when selecting between threads and processes

  • Type of work (IO-bound, computation, etc.)
  • Lifetime (Short vs Long)
  • Scheduling
  • Resource Sharing
  • Data Sharing
  • Communication
  • Thread/Process security and safety
  • Control and Synchronization
  • Environment and technology stack