DEV Community

David Hwang
David Hwang

Posted on

5/22 TIL: Processes, Contrapositive, etc.

--Systems--

Processes

  • A process is an instance of an executing program; each process has a unique process id & its parent process id
  • Virtual memory of a process is logically divided into:
    • Text initialized & uninitialized
    • Data
    • Stack - a series of frames with a new frame being added as a function is invoked & removed when the function returns; each frame contains local variables, function arguments, and called linkage information for a single function implication
    • Heap
  • Command line arguments supplied when a program is invoked are made available via argc and argv arguments to the main function

#include<unistd.h>

int proc_id = getpid();

int par_proc_id = getppid();

Enter fullscreen mode Exit fullscreen mode

Memory Allocation


malloc() // memory allocation

calloc() // contiguous allocation

free() // de-allocate

realloc() // re-allocate

// example

int* ptr

int num=8;

ptr = (int*)malloc(num*sizeof(int))

Enter fullscreen mode Exit fullscreen mode

System Limits

  • SUSV3 (Single Unix Specification V3) adds a lot of new functions into C/C++ library
  • SUSV3 specifies limits that an implementations may enforce and system options that an implementation may support

#include <limits.h>

LONG_MIN, LONG_MAX, CHAR_MIN, CHAR_MAX // etc

Enter fullscreen mode Exit fullscreen mode

--Discrete Math--

if p then q (p → q)
image

  • p → q ≡ ~p V q

~(p → q) ≡ ~(~p V q) ≡ (~~p ʌ ~q) ≡ p ʌ ~q

  • apply DeMorgan's Law
  • the only scenario where p → q is false is when p is T and q is F. Negating that p → q would be F. So this is equivalent to p ʌ ~q where p is T and q is F.

Contrapositive of a conditional

p → q ≡ ~q → ~p because

  • p → q ≡ ~p V q and
  • ~q → ~p ≡ q V ~p
  • with ~p V qq V ~p being true

Converse: p → q is the statement q → p (not logically equivalent)

Inverse: p → q is the statement ~p → ~q (contrapositive of a converse)

  • conclusion: converse ≡ inverse since contrapositive statements are logically equivalent

Biconditional p ↔ q

  • a conjunctive statement where we have both p → q and q → p implications
  • "if and only if"

Top comments (0)