Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How can a file be locked for a certain time? Post 44581 by natter on Monday 8th of December 2003 03:55:39 PM
Old 12-08-2003
Same problem, kinda

I have this same problem except when I create the semaphore file using a shell script, what happens if the shell script fails and the semaphore file is sitting out there forever?

So, the next time the script runs, it sees the semaphore file and doesn't run.

I need something like a 'finally' block in Java where if the shell script bails out, it needs to remove the semaphore file.

Any idea how to do this using shell scripting?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Lock a file. AND Wait if file is locked

Hi, I want to do the foll steps: 1. Check if someone has a lock on my file1. 2. if file1 is locked by any other user wait in a loop till another user releases lock 3. when lock released, lock file1. 4. do procesing (write) on file1. 5. processing complete. release lock on file1. ... (2 Replies)
Discussion started by: sunil_neha
2 Replies

2. Shell Programming and Scripting

checking whether a file is locked

hi Guys, I just wondering how I can check and ensure a file is not locked by another process. I need to modify a file using sed but I need to ensure that is not being modified by another process at the same time. Thanks. Harby. (2 Replies)
Discussion started by: hariza
2 Replies

3. Shell Programming and Scripting

Convert Epoch time format to normal date time format in the same file

I have a file named "suspected" with series of line like these : {'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''} {'protocol': 17, 'service': 'BitTorrent... (3 Replies)
Discussion started by: rk4k
3 Replies

4. UNIX for Advanced & Expert Users

How to list locked file in unix?

Hi, I want to list out all files which are lock by some process. ex- ~/critical I want to list all files in critical directory which has been locked. I need this very badly. Any suggestion highly appriciated. Regards, Ashok (1 Reply)
Discussion started by: ashokd001
1 Replies

5. UNIX for Dummies Questions & Answers

find locked files, print file path, unlock file

using OS X and the Terminal, I'd like to find all locked files in a specified directory, unlock them, and print a list of those files that were unlocked how can I do this? I'm familiar with chflags nouchg for unlocking one file but not familiar with unix enough to do what I'd like. Thanks! (0 Replies)
Discussion started by: alternapop
0 Replies

6. Solaris

fssnap error :snapshot error: File system could not be write locked

Hi Guys. This is part of my filesystem structure : Filesystem size used avail capacity Mounted on /dev/md/dsk/d0 47G 5.2G 42G 12% / /devices 0K 0K 0K 0% /devices ctfs 0K 0K 0K 0% ... (2 Replies)
Discussion started by: aggadtech08
2 Replies

7. Shell Programming and Scripting

Check if file is locked otherwise gzip it

Dear community, I've a continuos tcpdump on redhat that close the dumped file every 100000 captured packets. To avoid disk full I would like to gzip the closed *.cap file. But how can I check if the file is currently opened by tcpdump and skip it from gzip? Thanks! EDIT: Just to post an... (9 Replies)
Discussion started by: Lord Spectre
9 Replies

8. UNIX for Dummies Questions & Answers

UNIX Account getting Locked Everyday between same Time Frame

I am facing an Issue with a particular Unix Account ( ie a particular Userid) getting LOCKED everyday between 7:30am and 8:00am. The Password associated with this particular Account has been setup such that it should never Expire at all but it does LOCK the Account after more than 3 failed... (5 Replies)
Discussion started by: pchegoor
5 Replies

9. Shell Programming and Scripting

How to kill the process when the file is locked?

I was trying to read the file to create a table in SAS and I got error as follows while I read. Resource is write-locked by another user. File =/usr/sas/sas_config/Lev1/SASApp/StoredProcessServ​er/Logs/SASApp_STPServer_2015-09-29_tmp_18208.log. System Error Code = 0. ERROR: File is in... (10 Replies)
Discussion started by: Ram Kumar_BE
10 Replies

10. Shell Programming and Scripting

How to check the file locked or in use at FTP?

Hi Experts, I am beginner to shell scripting, I have a archive script which will connect to the FTP server and archive the files from FTP source location to FTP archive location. Now the problem here is, the script working for few files and not working for few.I am facing the below error... (1 Reply)
Discussion started by: spidy
1 Replies
sem_post(2)							System Calls Manual						       sem_post(2)

NAME
sem_post - unlock a POSIX semaphore SYNOPSIS
DESCRIPTION
is used to post the semaphore referenced by sem. The calling thread will not return from its call to unless it can either: increment the semaphore value, if there are no blocked threads on this semaphore; give the semaphore to a blocked thread, if there are any blocked threads on this semaphore; or have an error condition. If the semaphore value is < 0, the semaphore has blocked threads, waiting for it to become available (the absolute value of the semaphore's value indicates the number of waiters at that moment). If the semaphore value is >= 0, the semaphore has no waiters. If the semaphore has no waiters at the time its value is checked, the semaphore's value will be atomically incremented, with respect to the checking of its value, up to its maximum value as specified by If the semaphore has waiters at the time its value is checked, the semaphore value is not changed. Instead, the calling thread will attempt to wake up a waiter. If the semaphore has waiters having realtime priori- ties, the thread must wake up the highest priority waiter. Otherwise the thread at the head of the channel queue is woken up. When a waiter is successfully woken, the semaphore being posted will be given to the woken waiter. In other words, the state of the sema- phore remains unchanged. Instead, the semaphore being posted will be inherited by the waiter being woken from this call to If the specified semaphore referred to by sem is a named semaphore, then this semaphore must have been opened by the calling process with The calling process must have both read and write permissions on the semaphore to perform this operation. The routine may be called asyn- chronously, i.e. from a signal handler. To use this function, link in the realtime library by specifying on the compiler or linker command line. EXAMPLES
The following call to will post the semaphore sem. RETURN VALUE
A successful call to will return 0 and the calling thread would have posted the semaphore. Otherwise, the call to will return -1 with errno set to the appropriate value of the error condition. ERRORS
fails and does not perform the requested operation if any of the following conditions are encountered: [EPERM] The calling process does not have the privileges necessary to post the semaphore. [EINVAL] The argument sem does not refer to a valid semaphore. SEE ALSO
<semaphore.h>. STANDARDS CONFORMANCE
sem_post(2)
All times are GMT -4. The time now is 01:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy