LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-26-2009, 12:53 AM   #1
smartgupta
Member
 
Registered: Sep 2008
Posts: 81

Rep: Reputation: 15
Locking issue with serial port


Hi,
In my application,I need to monitor the devices connected through serial port in solaris sparc 9 OS.I used c and java code for it and I am able to do the same but the problem comes when I restart the system and the open my application and try to monitor it.but I m unable to monitor the devices and getting the message --

Quote:
Warning: The serial port "/dev/term/a" cannot be opened for use.
Please verify that it is entered correctly and that it is not already in use.
but when I delete /var/lock/LCK..a file.I am able to monitor again.

So plz let me know why it is happening and how to solve it.

Thanks in advance..
 
Old 08-26-2009, 08:46 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
It sounds like you simply need to perform a graceful shutdown of the system, in order for the lockfile(s) to be removed.
--- rod.
 
Old 08-26-2009, 11:06 AM   #3
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by theNbomr View Post
It sounds like you simply need to perform a graceful shutdown of the system, in order for the lockfile(s) to be removed.
Lock files, if used properly, shouldn't depend on graceful shutdown. They should be equally usable even with a crash caused, say, by power failure.

A lock file should be used by opening (creating, if necessary) the lock file and locking it. If for some reason the process which locks the file goes away, then the lock is removed from the file and some other process should be able to lock the file. There should never be a reason to actually remove the file.

But this message:
Quote:
Warning: The serial port "/dev/term/a" cannot be opened for use.
Please verify that it is entered correctly and that it is not already in use.
rather implies that the problem is not with the lock file, but with the serial port itself. Is that true? Look at the code which generates this message, and determine whether the message is triggered by:
  1. a failure opening the serial port itself;
  2. a determination that the lock file already exists;
  3. a failure to lock the lock file; or
  4. something else.
If it's (1), then maybe the code isn't using the lock file properly, and thinks that it's OK to continue, and then fails on opening the serial port.

If it's (2), then the code is not using lock files properly. Don't blow up if the lock file exists; blow up if you can't lock it. That's why it's called a lock file.

If it's (3), then somehow there's a process which already (or still) has the lock file locked. It's quite possible for you to delete a file that has a lock on it (and the lock will still continue to be on this phantom file). But if you delete it, your program can then go in and create a new lock file and lock it, oblivious to the fact that some other process thinks it still has the file locked.

This is the most likely possibility, since deleting the lock file lets your program run. Find out why it still has a lock on it. Which process has that file still open? To do that, when you encounter this difficulty, instead of just deleting the file, use lsof. For more information, enter this at the shell prompt:
Code:
man lsof
This should open your eyes to what else is going on that you might not have considered.

Hope this helps.
 
Old 09-22-2009, 01:40 AM   #4
smartgupta
Member
 
Registered: Sep 2008
Posts: 81

Original Poster
Rep: Reputation: 15
Hi,

I checked the code and i found out that when i restart the system,locked file is present in /var/lock dir but my application is unable to communicate it and throws the exception-

Quote:
Warning: The serial port "/dev/term/a" cannot be opened for use.
Please verify that it is entered correctly and that it is not already in use.
it shows that after restarting the system link is being broken but I am unable to get the right thing to resolve it.

Please provide ur valuable ideas..

thanks in advance....
 
Old 09-22-2009, 03:16 AM   #5
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by smartgupta View Post
Hi,

I checked the code and i found out that when i restart the system,locked file is present in /var/lock dir but my application is unable to communicate it and throws the exception-



it shows that after restarting the system link is being broken but I am unable to get the right thing to resolve it.

Please provide ur valuable ideas..

thanks in advance....
If the orphan lock file is created by your application, then the remedy is to rewrite your application to remove the lock file no matter how it is shut down.

1. Change your code to be more bulletroof about how it shuts itself down.

2. Test your changes by running the application and then forcing an abnormal exit:

Code:
# kill -9 (your process ID)
See if the lockfile is removed during this kind of exit. If it is not, learn how to properly exit shell scripts.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Serial port issue smartgupta Solaris / OpenSolaris 3 11-24-2008 06:24 AM
Serial port issue... ramesh6056 Linux - Software 1 11-29-2007 03:47 AM
Serial Port issue w0und3d Mandriva 10 03-22-2005 01:59 AM
Serial ATA on Intel ICH5 - Kernel locking up Excalibur Linux - Hardware 1 01-20-2004 05:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration