printf anomaly after “fork()”

I note that <system.h> is a non-standard header; I replaced it with <unistd.h> and the code compiled cleanly. When the output of your program is going to a terminal (screen), it is line buffered. When the output of your program goes to a pipe, it is fully buffered. You can control the buffering mode by … Read more

What is the purpose of fork()?

fork() is how you create new processes in Unix. When you call fork, you’re creating a copy of your own process that has its own address space. This allows multiple tasks to run independently of one another as though they each had the full memory of the machine to themselves. Here are some example usages … Read more

How to use shared memory with Linux in C

There are two approaches: shmget and mmap. I’ll talk about mmap, since it’s more modern and flexible, but you can take a look at man shmget (or this tutorial) if you’d rather use the old-style tools. The mmap() function can be used to allocate memory buffers with highly customizable parameters to control access and permissions, … Read more

fork() branches more than expected?

The fork() primitive often stretches the imagination. Until you get a feel for it, you should trace out on paper what each operation is and account for the number of processes. Don’t forget that fork() creates a near-perfect copy of the current process. The most significant difference (for most purposes) is that fork()‘s return value … Read more

Differences between fork and exec

The use of fork and exec exemplifies the spirit of UNIX in that it provides a very simple way to start new processes. The fork call basically makes a duplicate of the current process, identical in almost every way. Not everything is copied over (for example, resource limits in some implementations) but the idea is … Read more

The difference between fork(), vfork(), exec() and clone()

vfork() is an obsolete optimization. Before good memory management, fork() made a full copy of the parent’s memory, so it was pretty expensive. since in many cases a fork() was followed by exec(), which discards the current memory map and creates a new one, it was a needless expense. Nowadays, fork() doesn’t copy the memory; … Read more

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