Skip to content

Instantly share code, notes, and snippets.

View hamadu's full-sized avatar

hamadu hamadu

View GitHub Profile
@hamadu
hamadu / pipe01.c
Last active September 6, 2017 13:25
pipe
#include <unistd.h>
#include <stdio.h>
int main(int argc, char* argv[]) {
int pipefd[2];
pipe(pipefd);
int readFd = pipefd[0];
int writeFd = pipefd[1];
@hamadu
hamadu / F.java
Last active August 21, 2017 13:25
ARC081-F
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class F {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
@hamadu
hamadu / mutex.c
Created August 7, 2017 23:00
mutex
#include <unistd.h>
#include <stdio.h>
#include <pthread.h>
int x;
pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
void add_x(int a) {
pthread_mutex_lock(&mut);
x += a;
@hamadu
hamadu / thread.c
Created August 7, 2017 16:15
thread
#include <unistd.h>
#include <stdio.h>
#include <pthread.h>
int global_num = 100;
void* another(void *arg) {
global_num = 200;
printf("hello from another thread: %d\n", global_num);
global_num = 300;
@hamadu
hamadu / wait.c
Last active August 7, 2017 14:50
wait
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void print_error_and_exit() {
printf("error(%d): %s\n", errno, strerror(errno));
exit(1);
}
@hamadu
hamadu / fork_exec.c
Created August 7, 2017 14:33
fork_exec
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void print_error_and_exit() {
printf("error(%d): %s\n", errno, strerror(errno));
exit(1);
}
@hamadu
hamadu / fork_open_read.c
Last active August 7, 2017 13:19
open then fork / fork then open(for each process)
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void print_error_and_exit() {
printf("error(%d): %s\n", errno, strerror(errno));
exit(1);
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void print_error_and_exit() {
printf("error(%d): %s\n", errno, strerror(errno));
exit(1);
@hamadu
hamadu / copy.c
Last active July 20, 2017 22:50
copy.c
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void error_and_exit() {
printf("error(%d): %s\n", errno, strerror(errno));
exit(EXIT_FAILURE);
@hamadu
hamadu / Main.java
Created June 28, 2017 13:08
CountDegree
import java.util.*;
public class Main {
public static void main(String[] args) {
long time = 0;
for (long s = 1 ; s <= 10 ; s++) {
int[] g = gen(s);
time += takeIHM(g);
}
System.out.println("done:" + time / 10 / 1000);