Skip to content

Instantly share code, notes, and snippets.

/*
* Author: NagaChaitanya Vellanki
*
*
*
* mtrace and muntrace example
*
* Running the program and sample output:
*
* gcc -Wall -pedantic -o mtrace_and_muntrace mtrace_and_muntrace.c
/*
* Author: NagaChaitanya Vellanki
*
*
* calloc and realloc example
* gcc -Wall -pedantic -o calloc_and_realloc calloc_and_realloc.c
* ------------------------------------------------------------
* export MALLOC_TRACE=/tmp/t
* ------------------------------------------------------------
* ./calloc_and_realloc
/*
* Author: NagaChaitanya Vellanki
*
*
* search for a key in an array,
* if key is found return pointer to key
* else return NULL
*/
#include <stdio.h>
/*
* Author: NagaChaitanya Vellanki
*
* ./read_passwd_file root 3
*
* sample output
* -------------------------------
* Read /etc/passwd file
* Login name: root
/*
*
* Author: NagaChaitanya Vellanki
*
*
* Read entries in the passwd one at a time using getpwent
*/
#include <pwd.h>
/*
* Author: NagaChaitanya Vellanki
*
*
* ./read_group_file sys 0
*
* sample output
* ---------------------
/*
* Author: NagaChaitanya Vellanki
*
*
* Read entries in the groups file one at a time
*/
#include <grp.h>
#include <stdio.h>
/*
* Author: NagaChaitanya Vellanki
*
* Refer to Listing 8-2 of LPI book
*
* Authenticate user against the /etc/shadow
* gcc -Wall -pedantic -o check_user_password check_user_password.c -lcrypt
*
* sudo ./check_user_password
/*
* Author: NagaChaitanya Vellanki
*
*
*
* uptime command implementation
*/
#include <errno.h>
/*
* Author: NagaChaitanya Vellanki
*
*see listing 10-2 of LPI book
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>