FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora Development

 
 
LinkBack Thread Tools
 
Old 07-12-2011, 12:13 PM
Dario Lesca
 
Default How to read /proc/locks in safe mode?

Hi, how to I can read in safe mode, from bash, the content
of /proc/locks?

On my system I have more than 7000/9000 line into /proc/locks and if I
read it with awk (or cat or grep or cp) the file change during the read
and my input is undefined and is not processable (see attach).

My target is read if a process lock a specific files (through its
i-node)

Someone can suggest me some kind of solution?

Many thanks?

--
Dario Lesca <d.lesca@solinos.it>
[root@host tmp]# awk 'NF!=8{print $0}' /proc/locks
753: POSIX ADVISORY RE ADVISORY READ 28710 08:21:4033908 2147483646 2147483646
33646 2147483646
4083: POSIX ADVISORY READ 30177 08:21:234624212147483646 2147483646
4141: POSIX A ADVISORY READ 10060 08:21:38488232 2147483646 2147483646
4242: POSIX ADVISORY WRITE 22794 fd:00:8610665 1177483646
4964: POSIX ADVISORY READ 26859 fd:00:8610674 218610665 81968 81968
[root@host tmp]# awk 'NF!=8{print $0}' /proc/locks
3
1236ORY READ 5438 08:11:656005 2147483646 2147483646
1745: POSIX ADVISOREAD 21580 08:21:1016440 2147483646 2147483646
2106: POSIX ADVISORY READ 6791 08:21:2572556 2147483646147483646
2977: POSIX ADVISORY DVISORY READ 27026 08:21:30442412 2147483646 2147483646
3079 ADVISORY READ 7743 08:21:9044011 2147483646 2147483646
3151: POSIX ADVISORY READ 5208 08:21:31490441 214748363646
3209: POSIX ADVISORY READ 4472 08:21:33686184 2147483646 21474846 2147483646
3678: POSIX ADVISORY READ 25376 08:21:26362714 1 2147483646 2147483646
3793: POSIX ADVISORY READ 235468:21:32474726 2147483646 2147483646
4184: POSIX ADVISORY READ 12598 fd:00:8610665 2147483646 2420 804420
4549: POSIX ADVISORY READ 17993 08:21:393646 2147483646
4594: POSIX ADVISORY R ADVISORY READ 21663 08:21:30507841 2147483646 2147483646
4608: POSIX ADVISORY READ 26557 08:21:40829334 2147483646 2147483DVISORY READ 9546 08:21:24461636 2147483646 214748
3646
5081: POSIX ADVISORY READ 28760 fd:00:8610665 2147483646 2147482: POSIX ADVISORY READ 28102 fd:00:8610674 21474836
46 2147483646
5202: POSIX ADVISORY READ 13321 fd:47483646 2147483646
5261: POSIX ADVISORY READ 26557 08:21:26557 08:21:40829345 2147483646 2147483646
5436: POSIX ADVISORY READ 4644 fd:00:8610665 21474883646
5615: POSIX AD 7204 fd:00:8610665 2147483646 2147483646
[root@host tmp]# awk 'NF!=8{print $0}' /proc/locks
245 ADVISORY READ 22358 fd:00:8610674 2147483646 2147483646
2571: POSIX ADVISORY READ 25681 08:21:26362713 880 2147483646 2147483646
3503: POSIX ADVISORY Y READ 813 08:21:26362714 2147483646 2147483646
3721: POSIX ADVISORY READ4094 fd:00:8610665 2147483646 2147483646
4141: POSIX ADVISORY READ 10060 08:21646 2147483646
4185: POSIX ADVISORY REIX ADVISORY READ 13404 08:21:1360328 2147483646 2147483646
4669:EAD 21663 08:21:30507363 2147483646 2147483646
4787: POSIX ADVISORY READ 21544 08Y READ 21544 08:21:39567804 2147483646 2147483646
4905: POSIX ADVISORY REA610674 2147483646 2147483646
4965: POSIX ADVISORY WRIIX ADVISORY WRITE 26469 fd:00:8610665 18748 18748
5203: POSIX ADVISORY READ 31657 fd:E 31657 fd:00:8610665 18966 18966
5261: POSIX 26557 08:21:40829335 2147483646 2147483646
5320: POSIX ADVISORY READ 9546 08:21:244619346 08:21:24461900 2147483646 2147483646
5364: PO 5855 08:21:16023796 2147483646 2147483646
5378: POSIX ADVISORY READ 5855 08:21:15978566 214748364147483646
5483: PORY READ 30648 fd:00:8610674 2147483646 2147483646
5498: POSIX A
5555: POSIX ADVISORY READ 2109708:21:20201483 2147483646 2147483646
5734: POSIX A758 08:21:26117116 2147483646 2147483646
5850: POSIX ADVISORY READ 22680 fd:00:8610674 2147483646 2POSIX ADVISORY READ 22680 fd:00:8610674 2147483646 21474
83646
[root@host tmp]#
--
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel
 
Old 07-15-2011, 09:26 AM
Dario Lesca
 
Default How to read /proc/locks in safe mode?

Il giorno mar, 12/07/2011 alle 14.13 +0200, Dario Lesca ha scritto:
> Hi, how to I can read in safe mode, from bash, the content
> of /proc/locks?
>
> On my system I have more than 7000/9000 line into /proc/locks and if I
> read it with awk (or cat or grep or cp) the file change during the read
> and my input is undefined and is not processable (see attach).
>
> My target is read if a process lock a specific files (through its
> i-node)
>
> Someone can suggest me some kind of solution?

Then, there are not solutions for my problem?

Or my question is not clear?

Via bash, what is the best method for know if a process lock a specific
files?

Thanks, (and sorry for my bad english)

--
Dario Lesca <d.lesca@solinos.it>

--
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel
 
Old 07-15-2011, 03:57 PM
Przemek Klosowski
 
Default How to read /proc/locks in safe mode?

On 07/15/2011 05:26 AM, Dario Lesca wrote:
> Il giorno mar, 12/07/2011 alle 14.13 +0200, Dario Lesca ha scritto:
>> Hi, how to I can read in safe mode, from bash, the content
>> of /proc/locks?
>>
>> On my system I have more than 7000/9000 line into /proc/locks and if I
>> read it with awk (or cat or grep or cp) the file change during the read
>> and my input is undefined and is not processable (see attach).

I can't think of anything to lock all the other processes on your system
while your awk/cat is running, other than raising the priority of your
process high enough.

Perhaps if you explained what you are trying to accomplish by your
processing of /proc/locks, people have some suggestions. Clearly your
situation is unusual---why do you have thousands of active locks? I
think a dozen or so is the norm (I have a fairly busy desktop with many
sessions and programs open, and 20 locks are active right now).
--
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel
 
Old 07-15-2011, 03:57 PM
Przemek Klosowski
 
Default How to read /proc/locks in safe mode?

On 07/15/2011 05:26 AM, Dario Lesca wrote:
> Il giorno mar, 12/07/2011 alle 14.13 +0200, Dario Lesca ha scritto:
>> Hi, how to I can read in safe mode, from bash, the content
>> of /proc/locks?
>>
>> On my system I have more than 7000/9000 line into /proc/locks and if I
>> read it with awk (or cat or grep or cp) the file change during the read
>> and my input is undefined and is not processable (see attach).

I can't think of anything to lock all the other processes on your system
while your awk/cat is running, other than raising the priority of your
process high enough.

Perhaps if you explained what you are trying to accomplish by your
processing of /proc/locks, people have some suggestions. Clearly your
situation is unusual---why do you have thousands of active locks? I
think a dozen or so is the norm (I have a fairly busy desktop with many
sessions and programs open, and 20 locks are active right now).
--
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel
 
Old 07-15-2011, 04:21 PM
Dario Lesca
 
Default How to read /proc/locks in safe mode?

Il giorno ven, 15/07/2011 alle 11.57 -0400, Przemek Klosowski ha
scritto:
>
> I can't think of anything to lock all the other processes on your
> system while your awk/cat is running, other than raising the priority
> of your process high enough.
>
> Perhaps if you explained what you are trying to accomplish by your
> processing of /proc/locks, people have some suggestions. Clearly your
> situation is unusual---why do you have thousands of active locks? I
> think a dozen or so is the norm (I have a fairly busy desktop with
> many sessions and programs open, and 20 locks are active right now).

thanks Przemek

It's a server, and every user (>300) have ad least a lock on a specific
portion of the same file

The file /proc/locks contain also many other (<5000) lines than those
lock and this virtual file is continuously modified.

If I try copy it (cp /proc/locks /tmp/l or cat /proc/locks>/tmp/l) two
times in succession, the result is always very different and the
abnormal line (more than 8 field) are like attachment of previous
message.

So, if I process this file with awk the result many time is
undefined ...

My goal is extract the lock line of a specific process an see if this
process lock a specific file and extract the offset lock.

This procedure work if none of user login or logout on the server, but
this condition is rare...

today have check the lslk utilities, but even it, if user login/logout
and work do not show the correct list: some time the result is wrong...

Thanks

--
Dario Lesca <d.lesca@solinos.it>

--
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel
 
Old 07-15-2011, 04:21 PM
Dario Lesca
 
Default How to read /proc/locks in safe mode?

Il giorno ven, 15/07/2011 alle 11.57 -0400, Przemek Klosowski ha
scritto:
>
> I can't think of anything to lock all the other processes on your
> system while your awk/cat is running, other than raising the priority
> of your process high enough.
>
> Perhaps if you explained what you are trying to accomplish by your
> processing of /proc/locks, people have some suggestions. Clearly your
> situation is unusual---why do you have thousands of active locks? I
> think a dozen or so is the norm (I have a fairly busy desktop with
> many sessions and programs open, and 20 locks are active right now).

thanks Przemek

It's a server, and every user (>300) have ad least a lock on a specific
portion of the same file

The file /proc/locks contain also many other (<5000) lines than those
lock and this virtual file is continuously modified.

If I try copy it (cp /proc/locks /tmp/l or cat /proc/locks>/tmp/l) two
times in succession, the result is always very different and the
abnormal line (more than 8 field) are like attachment of previous
message.

So, if I process this file with awk the result many time is
undefined ...

My goal is extract the lock line of a specific process an see if this
process lock a specific file and extract the offset lock.

This procedure work if none of user login or logout on the server, but
this condition is rare...

today have check the lslk utilities, but even it, if user login/logout
and work do not show the correct list: some time the result is wrong...

Thanks

--
Dario Lesca <d.lesca@solinos.it>

--
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel
 
Old 07-15-2011, 04:48 PM
Dan Mills
 
Default How to read /proc/locks in safe mode?

On Fri, 2011-07-15 at 18:21 +0200, Dario Lesca wrote:

> If I try copy it (cp /proc/locks /tmp/l or cat /proc/locks>/tmp/l) two
> times in succession, the result is always very different and the
> abnormal line (more than 8 field) are like attachment of previous
> message.

The thing is ANY processing is inherently going to be racy, at least
some of the time.

The way to find out of part of a file is locked, is to try to take the
lock yourself (LOCK_NB as an argument to flock may be useful here), if
you get it then it was not held, and if your attempt fails then the lock
is held by something else.

ANYTHING else is going to give you inherently out of date information
that may change from under you.

You really need to find another way to do whatever it is you are really
trying to do, why does a third party need to know which locks are held?

Regards, Dan.



--
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel
 
Old 07-15-2011, 05:04 PM
Dario Lesca
 
Default How to read /proc/locks in safe mode?

Il giorno ven, 15/07/2011 alle 17.48 +0100, Dan Mills ha scritto:
> The thing is ANY processing is inherently going to be racy, at least
> some of the time.
>
> The way to find out of part of a file is locked, is to try to take the
> lock yourself (LOCK_NB as an argument to flock may be useful here),
> if you get it then it was not held, and if your attempt fails then the
> lock is held by something else.

Ok, this is a way for try to resolve my problem, I check it. Thanks

> ANYTHING else is going to give you inherently out of date information
> that may change from under you.
yes, i saw it

> You really need to find another way to do whatever it is you are
> really trying to do, why does a third party need to know which locks
> are held?

Because is a third part software and the producer do not give us that
information, so I thought read /proc/locks for establish if a process is
active via our lock on this file.

Ok, thank Dan for suggest.

Ciao

--
Dario Lesca <d.lesca@solinos.it>

--
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel
 
Old 07-15-2011, 05:33 PM
Thomas Moschny
 
Default How to read /proc/locks in safe mode?

2011/7/12 Dario Lesca <d.lesca@solinos.it>:
> Hi, how to I can read in safe mode, from bash, the content
> of /proc/locks?
>
> On my system I have more than 7000/9000 line into /proc/locks and if I
> read it with awk (or cat or grep or cp) the file change during the read
> and my input is undefined and is not processable (see attach).

Interesting, because afaiu, in recent kernels reading /proc/locks
line-wise should not yield broken records, as the code in fs/locks.c
uses the seq_file abstraction. See
http://stackoverflow.com/questions/5713451/is-it-safe-to-parse-a-proc-file/5880485#5880485.
What is the kernel version you are seeing that on?

- Thomas
--
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel
 
Old 07-19-2011, 12:05 PM
Dario Lesca
 
Default How to read /proc/locks in safe mode?

Il giorno ven, 15/07/2011 alle 19.33 +0200, Thomas Moschny ha scritto:
> Interesting, because afaiu, in recent kernels reading /proc/locks
> line-wise should not yield broken records, as the code in fs/locks.c
> uses the seq_file abstraction. See
> http://stackoverflow.com/questions/5713451/is-it-safe-to-parse-a-proc-file/5880485#5880485.
> What is the kernel version you are seeing that on?

Thanks Thomas for reply, but ...

... Opss! I have verify and this server is the only server with a Centos
5.5 with kernel 2.6.18-194.32.1.el5. (sorry for the OT)

On another 2 systems with fedora 14 (I thought it was one of these
servers with the error) the problem does not occur, but on these server
there are fewer users connected
Currently I do not have the ability to update the C5.5 server, but I
will as soon as possible
So my read /proc/locks problem it might be a kernel's problem?

Thanks for reply

--
Dario Lesca <d.lesca@solinos.it>

--
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel
 

Thread Tools




All times are GMT. The time now is 09:20 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org