How to share memory between processes created by fork()?

You can use shared memory (shm_open(), shm_unlink(), mmap(), etc.). #include <stdio.h> #include <stdlib.h> #include <sys/mman.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> static int *glob_var; int main(void) { glob_var = mmap(NULL, sizeof *glob_var, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); *glob_var = 1; if (fork() == 0) { *glob_var = 5; exit(EXIT_SUCCESS); } else { … Read more

Continue PHP execution after sending HTTP response

I had this snippet in my “special scripts” toolbox, but it got lost (clouds were not common back then), so I was searching for it and came up with this question, surprised to see that it’s missing, I searched more and came back here to post it: <?php ob_end_clean(); header(“Connection: close”); ignore_user_abort(); // optional ob_start(); … Read more

fork: retry: Resource temporarily unavailable [closed]

This is commonly caused by running out of file descriptors. There is the systems total file descriptor limit, what do you get from the command: sysctl fs.file-nr This returns counts of file descriptors: <in_use> <unused_but_allocated> <maximum> To find out what a users file descriptor limit is run the commands: sudo su – <username> ulimit -Hn … Read more

Forking vs Threading

The main difference between forking and threading approaches is one of operating system architecture. Back in the days when Unix was designed, forking was an easy, simple system that answered the mainframe and server type requirements best, as such it was popularized on the Unix systems. When Microsoft re-architected the NT kernel from scratch, it … Read more

Visually what happens to fork() in a For Loop

Here’s how to understand it, starting at the for loop. Loop starts in parent, i == 0 Parent fork()s, creating child 1. You now have two processes. Both print i=0. Loop restarts in both processes, now i == 1. Parent and child 1 fork(), creating children 2 and 3. You now have four processes. All … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)