Skip to content

Instantly share code, notes, and snippets.

--sandbox_writable_path=/home/$USER/.ccache
Use --sandbox_debug to see verbose messages from the sandbox
ccache: error: Failed to create temporary file for /home/satish/.ccache/tmp/trees.stdout: Read-only file system
#!/bin/python
# except for the top level directory we ignore
# hidden files and directories by default
# arg1 : directory arg2 : outputfile.png
import sys
import os
import os.path
import networkx as nx
import matplotlib.pyplot as plt
@eerpini
eerpini / blog_shared_memory_mmap.c
Last active August 29, 2015 14:15
Simple shared memory example using mmap
/*
* get the definition of MAP_ANONYMOUS
*/
#define _BSD_SOURCE
#include <stdio.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
#include <string.h>
int main (int argc, char **argv)
{
int fd, i, block, blocksize, bcount, prev_block, frag_count=0;
struct stat st;
assert (argv[1] != NULL);
assert (fd = open (argv[1], O_RDONLY));
assert (ioctl (fd, FIGETBSZ, &amp;blocksize) == 0);
assert (!fstat (fd, &amp;st));
bcount = (st.st_size + blocksize - 1) / blocksize;
printf ("File: %s Size: %d Blocks: %d Blocksize: %d\n",
int * string_indices= break_by_spaces("A String of words");
for(i=0; *(string_indices + i) != -1; i++){
fprintf(stdout, "[%d] %d %s \n", i, *(string_indices + i), (char *)(argv[1] + *(string_indices + i)));
}
@eerpini
eerpini / split_spaced_string.c
Last active August 29, 2015 14:15
Split a string with spaces into null terminated strings.
int * break_by_spaces(char * arg){
if(strlen(arg) &lt;= 0 || (strlen(arg) ==1 &amp;&amp; *arg == ' ')){
return NULL;
}
int * retval = malloc((strlen(arg) -1)*sizeof(int));
int * temp = retval;
int counter = 0;
if(retval == NULL){
perror("malloc");
exit(EXIT_FAILURE);
@eerpini
eerpini / numa-memory-at-each-node.c
Created February 18, 2015 21:53
Get the memory at each node in a NUMA system.
#include <numa.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv){
long free;
int num_cpus = 4;
long node_size = -1L;
int i;
@eerpini
eerpini / read-utmp-file.c
Last active February 19, 2020 19:02
sample code to read the unix session log utmp
#include <utmpx.h>
#include <paths.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv){
struct utmpx data;
FILE *log_file = fopen(_PATH_UTMP, "r");
memset(&amp;data, 0, sizeof(struct utmpx));
@eerpini
eerpini / struct-utmpx.c
Last active August 29, 2015 14:15
The structure definition for the session log entry
/* The structure describing an entry in the user accounting database. */
struct utmpx
{
short int ut_type; /* Type of login. */
__pid_t ut_pid; /* Process ID of login process. */
char ut_line[__UT_LINESIZE]; /* Devicename. */
char ut_id[4]; /* Inittab ID. */
char ut_user[__UT_NAMESIZE]; /* Username. */
char ut_host[__UT_HOSTSIZE]; /* Hostname for remote login. */
struct __exit_status ut_exit; /* Exit status of a process marked as DEAD_PROCESS. */