Master system-level programming, memory management, and advanced algorithms - one step at a time.
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#define THREAD_COUNT 4
void *parallel_task(void *arg) {
int thread_id = *(int*)arg;
printf("Thread %d executing\n", thread_id);
return NULL;
}
int main() {
pthread_t threads[THREAD_COUNT];
int thread_args[THREAD_COUNT];
for(int i = 0; i < THREAD_COUNT; i++) {
thread_args[i] = i;
pthread_create(&threads[i], NULL,
parallel_task,
&thread_args[i]);
}
for(int i = 0; i < THREAD_COUNT; i++) {
pthread_join(threads[i], NULL);
}
return 0;
}
Access our high-performance computing environment for hands-on system programming experience.
Ubuntu 20.04 LTS
GCC, GDB, Valgrind
int *ptr = (int*)malloc(32);
*ptr = 42; // Write to 0x00
*(ptr + 1) = 84; // Write to 0x04
pid_t pid = fork();
if (pid == 0) {
// Child process
execl("/bin/ls", "ls", "-l", NULL);
} else if (pid > 0) {
// Parent process
wait(NULL);
printf("Child completed\n");
}