Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do all types of interprocess/interthread communication need system calls?

In Linux,

  1. do all types of interprocess communication need system calls?

    Types of interprocess communication are such as

    Pipes
    Signals
    Message Queues
    Semaphores
    Shared Memory
    Sockets
    
  2. Do all types of interthread communication need system calls?

I would like to know if all interprocess communications and interthread communications involve switching from user mode to kernel mode so that the OS kernel will run to perform the communications? Since system calls all involve such switch, I asked if the communications need system calls.

For example, "Shared memory" can be used for both interprocess and interthread communcations, but i am not sure if it requires system calls or involvement of OS kernel to take over the cpu to perform something.

Thanks.

like image 776
Tim Avatar asked Sep 13 '25 04:09

Tim


1 Answers

For interprocess communication I am pretty sure you cannot avoid system calls.

For interthread communication I cannot give you a definitive answer, but my educated guess would be "yes-and-no". You see, you can communicate between threads using thread-safe queues, and the only thing that a thread-safe queue needs in order to work is a lock. If a lock is unavailable at the moment that a thread wants to obtain it, then of course the system must be involved in order to put the thread in a waiting mode. But if the lock is available to obtain, then the thread should be able to proceed without the need for any system call.

That's what I would guess, and I would be quite disappointed to find out that things do not actually work this way, because that would mean that code which I have up until now been considering pretty innocent in fact has a tremendous additional hidden overhead.

like image 149
Mike Nakis Avatar answered Sep 14 '25 20:09

Mike Nakis