Sponsored Content
Full Discussion: How to Lock In HP-UX
Operating Systems HP-UX How to Lock In HP-UX Post 302079058 by Perderabo on Thursday 6th of July 2006 03:18:42 PM
Old 07-06-2006
I just tested manditory locking in HP-UX and it works as well as it works for any other version of unix.
Code:
$ chmod 666 datafile
$ cp datafile1 datafile
$ ./locktest &
[1]     1302
$ cp datafile2 datafile
$ datafile2 line 1
datafile2 line 2
$
[1] +  Done                    ./locktest &
$
$
$ cp datafile1 datafile
$ chmod 2666 datafile
$ ./locktest &
[1]     1330
$ cp datafile2 datafile
cp: cannot create datafile: Resource temporarily unavailable
$ datafile1 line 1
datafile1 line 2
$
[1] +  Done                    ./locktest &
$
$ uname -srv
HP-UX B.11.00 A
$ cat locktest.c
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>

main(void)
{
        char buff[250];
        FILE *F;
        struct flock mylock;
        int fd, iret;
        fd = open("datafile", O_RDWR);

        mylock.l_type = F_WRLCK;
        mylock.l_whence = SEEK_SET;
        mylock.l_start = 0;
        mylock.l_len = 0;
        iret = fcntl(fd,F_SETLK, &mylock);
        if (iret == -1) {
                 if ((errno == EACCES) || (errno == EAGAIN)) {
                        printf("locked \n");
                        exit(1);
                } else {
                        printf("fcntl failed\n");
                        exit(1);
                }
        }
        sleep(30);
        F = fdopen(fd, "r");
        while (fgets(buff,250,F)) {
                fputs(buff,stdout);
        }
        exit(0);
}

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to lock keyboard without using lock command

how can I lock my keyboard while I'm away from the computer without using lock command. What other commands gives me the option to lock keyboard device? thanks (7 Replies)
Discussion started by: dianayun
7 Replies

2. UNIX for Dummies Questions & Answers

Lock File

Hi, We have a lock file being created called lck8c0001 created in Unixware 2.1.2. This is locking a printer. According to some websites, 8c0001 relates to the device name. How does one link 8c0001 to those devices listed in the /dev folder? I have done a ps -lp for all printers and have... (4 Replies)
Discussion started by: canman
4 Replies

3. Shell Programming and Scripting

Lock for this script

Hi, My requirement is to service a process and below is the script which i wrote for that and works fine, I have kept it in a crontab and running this everyminute, how do I lock this if its already running and i dont want to open if its running and not completed yet. The crontab need to run... (4 Replies)
Discussion started by: strunz
4 Replies

4. Shell Programming and Scripting

lock an account

hi how can I Lock an account, by prepending ”*LK*” to the password field in /etc/shadow. I dont want to use passwd -l . Any idea? (3 Replies)
Discussion started by: tjay83
3 Replies

5. Solaris

Not able to lock the port

Hi, I am working with Sun-Solaris 9 and in our application I need to connect the UPS with Serial port,after that I need to monitor it..but before stating communication,It should lock that port,To check it,first i am trying to make sure the lock directory exists and I am able to find it(/var/lock)... (0 Replies)
Discussion started by: smartgupta
0 Replies

6. Red Hat

Security Question: Lock after invalid login, Session Lock and Required Minimum Password Length

Hello all, If anyone has time, I have a few questions: How do I do the following in Linux. We are using Red Hat and Oracle Enterprise Linux, which is based on Red Hat too. 1. How to lock the account after a few (like 3) invalid password attempts? 2. How do you lock a screen after 30... (1 Reply)
Discussion started by: nstarz
1 Replies

7. UNIX for Advanced & Expert Users

Testing privileges -lock lockfile /var/lock/subsys/..- Permission denied

Hi all, I have to test some user priviliges. The goal is to be sure that an unauthorized user can't restart some modules (ssh, mysql etc...). I'm trying to automate it with a shell script but in same cases I got the syslog broadcast message. Is there any way to simply get a return code... (3 Replies)
Discussion started by: Dedalus
3 Replies

8. Shell Programming and Scripting

lock on files

Hi, I want to write a code where in the file once taken genrates a lock number and other developer/user cannot take the file to make any changes in it. He gets the file only as read only. (2 Replies)
Discussion started by: rac
2 Replies

9. Ubuntu

Help me to lock my system.

Hi All! I am not able to lock my Ubuntu 12.04 LXDE. Can anybody tell me the shortcut to lock the system. I have tried all conventional keyboard shortcuts as well as buttons. (2 Replies)
Discussion started by: nixhead
2 Replies

10. Shell Programming and Scripting

Need help in lock and unlock and after the changes

Requirement:First i need to unlock the directory which i had a script for it.If i select app1 it should unlock the directory and after chnages in the script once need to lock the directory with lock command The below highlighed variables in lock and unlock has to be changed according... (2 Replies)
Discussion started by: bhas85
2 Replies
load_datafile_object(3alleg4)					  Allegro manual				     load_datafile_object(3alleg4)

NAME
load_datafile_object - Loads a specific object from a datafile. Allegro game programming library. SYNOPSIS
#include <allegro.h> DATAFILE *load_datafile_object(const char *filename, const char *objectname); DESCRIPTION
Loads a specific object from a datafile. This won't work if you strip the object names from the file, and it will be very slow if you save the file with global compression. Example: /* Load only the music from the datafile. */ music_object = load_datafile_object("datafile.dat", "MUSIC"); /* Play it and wait a moment for it. */ play_midi(music_object->dat); ... /* Destroy unneeded music. */ unload_datafile_object(music_object); RETURN VALUE
Returns a pointer to a single DATAFILE element whose `dat' member points to the object, or NULL if there was an error or there was no object with the requested name. Remember to free this DATAFILE later to avoid memory leaks, but use the correct unloading function! SEE ALSO
unload_datafile_object(3alleg4), load_datafile(3alleg4), set_color_conversion(3alleg4), find_datafile_object(3alleg4), regis- ter_datafile_object(3alleg4) Allegro version 4.4.2 load_datafile_object(3alleg4)
All times are GMT -4. The time now is 05:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy