- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Open & locking files
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-23-2010 01:19 PM
тАО04-23-2010 01:19 PM
Solved! Go to Solution.
- Tags:
- nflocks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-23-2010 02:30 PM
тАО04-23-2010 02:30 PM
Solution#include
#include
main()
{
static char buf [8192];
while( scanf("%s",&buf)>0)
{
int f;
f=open(buf,O_RDWR,0);
if (f<0) { perror(buf); continue; }
if (lockf(f,F_TLOCK,4096))
printf("%s already locked\n",buf);
else
printf("%s locked\n",buf);
}
sleep (100000);
}
a.out
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-23-2010 02:30 PM
тАО04-23-2010 02:30 PM
Re: Open & locking files
There is open(2) and fcntl(2) or lockf(2).
You could use a script to read that file and put the files on the command line of your program:
lock-prog $(< file-list)
Then just loop on argv and open and lock each file.
You can only open up to maxfiles_lim(5) so you will have to increase that kernel parm, or run multiple instances of your lock-prog.
I suppose you could create a 1 Mb file and lock each byte separately and not need to open each file in your list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-23-2010 02:57 PM
тАО04-23-2010 02:57 PM
Re: Open & locking files
where do I modify the code to put my filename that has this list of filenames? I am not a C programmer, I do understand a little of the code.
Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-23-2010 03:16 PM
тАО04-23-2010 03:16 PM
Re: Open & locking files
> where do I modify the code to put my filename that has this list of filenames?
You don't have to modify anything, Compile Laurent's code and redirect the file of your choice to be its input as he showed:
# a.out < filenames
Regards!
...JRF...