Linux/Unix
Multiple child processes (Recursive-fork)
A simple recursive code to demonstrate how, a fork command can be invoked into a function, that may call the fork till arguments reach the end, with a tree that would work, printing the buffer with command line arguments. It happens to print in a specific order, from the end to the start without an exit(0) function.
___________________________________________________________________________________
Use of 'endl' in a 'Cout' Stream for 'dup2'
Cases of Flushing:
___________________________________________________________________________________
A case of 'named pipe' exception
Server Side.c
What does Unlink() do?
Unlink() happens to remove the file object from the filesystem, so that it goes away, like an unnamed pipe. However, the case that happened to cause this was:
Once a pipe has been created, another attempt to create would result in an error, basically an error that would point that the file already exists, and that would happen to either (a) stuck the program or (b) cause an evil loop, if there is one and the program somehow skips the error.
The unlink() managed to remove the pipe so that the next launch would create the FIFO obj again, hence the proper working. I am still, doubtful of the circumstances under which this happened to take place, and if another such exception throws up, a diagnosis to carry out the possible causes will be listed in this again.
___________________________________________________________________________________
Using 'mmap' in shared memory
The code given above is a simple demonstration of using 'mmap' to map some content onto virtual memory space. Let's clarify this a bit more:
- The file descriptor opens the file
- The mmap() is called with the length of this file in the second parameter and the offset '0' in the last, basically the beginning of the file
- The contents are mapped for this length and a pointer to this is returned
- As seen, the pointer is a char*, which can be manipulated by indexes like a buffer to read the content or just use it
- In a client-server communication model, this pointer can be shared by 'shared memory loc'
- At the end, munmap() tends to delete the mappings
I didn't run into any errors during this, thus I haven't specified any here, as is routine. But, here are a few findings I'll enlist below:
- Mmap() is faster than system calls due to less context-switching (kernel to user, vice versa), and as stated by another user, due to vector type memory allocation.
- Mmap() uses page-sizes or, let's say, it uses the multiples of this, to make finding content easier. Let's say, we have page sizes starting from '0' to '4' to '8' to '12' to '16', which are all multiples of '4', thus one page here is, assumed, 4kB, so now, if I were to map files at an offset corresponding to these multiples, it would be easy to find it, and read out the data. Once again, if the length is bigger than a page size, it is mapped out on several pages which brings us to the last point
- Slack Space is an issue for smaller sizes
___________________________________________________________________________________
Why is pthread_join() important?
I recently carried out an experiment while working with pthreads in C, and found out that not using pthread_join() led to a failure in achieving desired results. Here is the experiment with socket-connections while working in Linux:
Here is the func:
There is a concept of deferred cancellation, an orderly cancel method for a thread or process to die. Deferred means to postpone, and basically, what it does is: A process may have a call in some other process for its cancellation, however, the call will only succeed, once a flag has been set by the process that has to be cancelled, that it should be cancelled. Process 2 may have a call for Process 1 cancellation, however, it will only execute the cancel call, once Process 1 sets the flag for its kill.
___________________________________________________________________________________











Comments
Post a Comment