What is Semaphore? Why it is important for server admin?

What is Semaphore? Why it is important for server admin?

What is Semaphore? Why it is important for server admin?

When saying about the process of multi-processing in Linux its must talk about semaphore. Mostly, we used to delete unwanted documents and files in the system for allocating free space right! In the same way, depends upon the status of the semaphore in the server you can delete unwanted entries that fill up unnecessary space in your system. IPC’s are also known as a process, you can communicate easily within the system so in that case, IPC helps you to improve the communication at all times.

If you check on definitions find the exact course of semaphore such as “Common resources are controlled using data types in abstract and variables. Here, we describe semaphore as abstract data type or variables which help to use multiple programs in the operating system. Applications will have a deep process to communicate with each other. Semaphore is an interface here to communicate between each application. Admin in Linux will often see an error message called “Device has no space”. Whenever you start web server apache, semaphore shows an error message called “Device has no space”.

Apache error: No space left on device: mod_rewrite: Parent could not create RewriteLock.
There is a common process of communication between the child process and the apache parent. Sometimes, apache won’t work properly it means the communication held there doesn’t give a proper response. If communication fails then the process won’t start normally. Semaphore will immediately lock the memory location and it won’t release the process in the next state. In the actual case, the parent process will kill the child process. But sometimes, it won’t kill the child process and goes to the next process directly. This is because; when the server goes at a high peak the parent process won’t kill the child process properly.

[error] (28)No space left on device: Cannot create SSLMutex

[crit] (28)No space left on device: mod_rewrite: Parent could not create RewriteLock file /usr/local/apache/logs/rewrite_lock Configuration Failed

[emerg] (28)No space left on device: Couldn't create accept lock

[notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)

[notice] Digest: generating secret for digest authentication ...

[notice] Digest: done

[warn] pid file /etc/httpd/run/httpd.pid overwritten -- Unclean shutdown of previous Apache run?

[emerg] (28)No space left on device: Couldn't create accept lock
Now apache server won’t be started by semaphore! We need to start the apache server manually right! It’s time to kill the child process for allowing semaphore to start the apache server now.

How to check semaphore status in the server?

To check the semaphore status in the server, you can use the command line mentioned below:

Here, you can see the semaphore status as described below:

# ipcs -s

------ Semaphore Arrays --------
key semid owner perms nsems
0x00000000 831324160 nobody 600 1
0x00000000 825327617 nobody 600 1
0x00000000 825360386 nobody 600 1
0x00000000 831356931 nobody 600 1
0x00000000 831389700 nobody 600 1
0x00000000 831422469 nobody 600 1
0x6103117e 256901126 skklin12 666 3
You can see the word “nobody” here! It means the problem is with semaphore and apache server which doesn’t have proper communication between it. To make apache server work in proper mode, then we have only one solution to kill all those process.

We have discussed more killing semaphore process. How to do it? Let’s have a deep explanation here:

Use the below-mentioned command to kill the process of a semaphore:

Its must to know the apache server name for killing those semaphore process so, use the command to know the apache server name:

for i in `ipcs -s | grep nobody | awk {'print $2'}`; do (ipcrm -s $i); done
or

for i in `ipcs -s | awk '/nobody/ {print $2}'`; do (ipcrm -s $i); done
or

ipcs -s | grep nobody | awk '{print $2}' | xargs -n 1 ipcrm sem
If you name the user apache as nobody then it kills the semaphore process.

How to get configuration details for semaphore using command?

To know the exact status of semaphore use below mentioned command:

Check on the sample listed below:

# ipcs -l

------ Messages Limits --------
max queues system wide = 32768
max size of message (bytes) = 65536
default max size of queue (bytes) = 65536

------ Shared Memory Limits --------
max number of segments = 4096
max seg size (kbytes) = 4194303
max total shared memory (kbytes) = 1073741824
min seg size (bytes) = 1

------ Semaphore Limits --------
max number of arrays = 128
max semaphores per array = 250
max semaphores system wide = 32000
max ops per semop call = 32
semaphore max value = 32767
Even if you find the problem exist continuously then go with another option by increasing the parameter of semaphore.

Increase the entry value /etc/sysctl.conf to change the parameter of semaphore:

kernel.msgmni = 1024
kernel.sem = 250 256000 32 1024
To ensure the changes made recently do run on the command sysctl -p

By now, you have completed good research on the semaphore. So, it's your turn to make sure of all the processes listed by semaphore. Keep your system space free by deleting unwanted files and semaphores!
Author
bhawanisingh
Views
3,540
First release
Last update
Rating
0.00 star(s) 0 ratings
Top