When an application crashes...

  • Thread starter Alexander Dong Back Kim
  • Start date
A

Alexander Dong Back Kim

Hi all,

I'm working on a Linux machine and using g++. I'm developing an
semaphore module for a number of applications in the system.

My question scenario is, an application can lock a resource which is
shared memory segment in this case, after they locked a segment and if
they somehow crash then the lock won't be released because the
application locked the resource is dead.

I hope there must be a way to release the lock so solve this problem
even the application is crashed unexpectedly.

Any idea?

best regards,

Alex D. B. Kim
 
R

red floyd

Alexander said:
Hi all,

I'm working on a Linux machine and using g++. I'm developing an
semaphore module for a number of applications in the system.

My question scenario is, an application can lock a resource which is
shared memory segment in this case, after they locked a segment and if
they somehow crash then the lock won't be released because the
application locked the resource is dead.

I hope there must be a way to release the lock so solve this problem
even the application is crashed unexpectedly.

What is your C++ question? You're OT here. Ask in a Linux newsgroup.

1. If your question makes sense if you change the language, then it's
OT in comp.lang.c++.
2. If you question would not make sense if you change your platform
(i.e. linux=>windows), then it's OT in comp.lang.c++.
 
L

lbonafide

I hope there must be a way to release the lock so solve this problem
even the application is crashed unexpectedly.

I think it would be better to find out why it's crashing and fix
that. If you post some code, maybe we can help.
 
P

peter koch

Hi all,

I'm working on a Linux machine and using g++. I'm developing an
semaphore module for a number of applications in the system.

My question scenario is, an application can lock a resource which is
shared memory segment in this case, after they locked a segment and if
they somehow crash then the lock won't be released because the
application locked the resource is dead.

I hope there must be a way to release the lock so solve this problem
even the application is crashed unexpectedly.

Any idea?

best regards,

Alex D. B. Kim

This should be possible with some kind of heavyweight structure, but
the interesting question is why you would ever want to do that! If the
application crashes while it holds the semaphore, this datastructure
should by definition be defined as corrupted.
As to how to do it, I suggest a Linux group.

/Peter
 
R

red floyd

peter said:
This should be possible with some kind of heavyweight structure, but
the interesting question is why you would ever want to do that! If the
application crashes while it holds the semaphore, this datastructure
should by definition be defined as corrupted.
As to how to do it, I suggest a Linux group.

He may be using SystemV IPC, which functions that way by design.
 
A

Alexander Dong Back Kim

What is your C++ question? You're OT here. Ask in a Linux newsgroup.

1. If your question makes sense if you change the language, then it's
OT in comp.lang.c++.
2. If you question would not make sense if you change your platform
(i.e. linux=>windows), then it's OT in comp.lang.c++.

so what? are you the manager of this group or what? If you don't know
the answer then just shut up.
 
A

Alexander Dong Back Kim

What is your C++ question? You're OT here. Ask in a Linux newsgroup.

1. If your question makes sense if you change the language, then it's
OT in comp.lang.c++.
2. If you question would not make sense if you change your platform
(i.e. linux=>windows), then it's OT in comp.lang.c++.

so what? are you the manager of this group or what? If you don't know
the answer then just shut up.
 
A

Alexander Dong Back Kim

This should be possible with some kind of heavyweight structure, but
the interesting question is why you would ever want to do that! If the
application crashes while it holds the semaphore, this datastructure
should by definition be defined as corrupted.
As to how to do it, I suggest a Linux group.

/Peter


Hi Peter,

The reason why I'm looking for this solution is, currently, I'm
developing an real time system using IPC. In the system, many
processes will run at the same time and they are independent from each
other. They also need to share their data so they are using shared
memory as a medium. However, since they can access and update the
shared memory simultaneously, I have been asked to implement a
implementation of a read/write lock for the multiple applications.
Therefore, I chose semaphore for this.

The problem of semaphore is, although they works beautifully, if a
process lock the semaphore and crashes immediately after the lock,
then the lock won't be unlocked. Therefore, there is no way other
applications can access the locked resource. Because of this reason, I
think I have to somehow protect unexpected terminations. In other
words, in order to unlock the resource before the process dies, I
think I have to catch some system message or destructor of the class.
I tried destructor way but it didn't call the destructor when the
application is unexpectedly killed.

Any suggestion for solving this problem?

Cheers,
 
I

Ian Collins

Alexander said:
so what? are you the manager of this group or what? If you don't know
the answer then just shut up.
You where given the correct answer, see above. Your question was a
Linux/Unix one rather than a C++ language one.
 
I

Ian Collins

Alexander said:
The problem of semaphore is, although they works beautifully, if a
process lock the semaphore and crashes immediately after the lock,
then the lock won't be unlocked. Therefore, there is no way other
applications can access the locked resource. Because of this reason, I
think I have to somehow protect unexpected terminations. In other
words, in order to unlock the resource before the process dies, I
think I have to catch some system message or destructor of the class.
I tried destructor way but it didn't call the destructor when the
application is unexpectedly killed.

Any suggestion for solving this problem?
Yes, ask the experts on either a linux group or comp.unix.programmer.
There are a number of issues tied up on your question, some are system
specific (Sys V IPC) other more generic programming (how do you manage
possibly corrupt shared data if process crashes with a lock held).

Have fun.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top