Git Product home page Git Product logo

flock_demo's Introduction

flock(2) demo for QNX Neutrino RTOS 7

Here is an simple example of using flock(2) on QNX Neutrino RTOS 7/x86. It hopefully make you aware that some filesystems (for example RAM disk filesystem on /tmp) do not support flock(2) call - will return Function not implemented.

Setup

You need to have installed QNX SDP 7.0. To run this demo you need also one target (VM is fine) with running QNX Neutrino RTOS 7. I tested it on QNX SDP 7.0 BSP for Generic x86 modified for VirtualBox Please see http://blackberry.qnx.com/en/developers/bsp for list of available BSPs.

Details of my target RTOS:

pidin info

CPU:X86 Release:7.0.0  FreeMem:598MB/639MB BootTime:Jul 21 09:00:31 GMT 2019
 Actual resident free memory:600Mb
Processes: 22, Threads: 51
Processor1: 263730 AMD ?86 F15M1qS2 2006MHz FPU

You may choose any of these options:

  • import this project into Momentics IDE
  • run make from CLI

To run make from CLI you need to:

  • setup environment variables and PATH for build using command like:

    source ~/qnx700/qnxsdp-env.sh
  • then you can just issue:

    make

    See comments at the top of Makefile how to build for other platforms (than x86 - 32-bit) and/or build type different from debug.

    For example to build x86_64 (64-bit) binary use:

    make clean all PLATFORM=x86_64

Running

To run binary you can use any of:

  • Run or Debug function from Momentics IDE

  • upload and run binary on QNX Neutrino RTOS target, for example using commands like:

    # replace 192.168.56.102 wiht IP of your QNX Neutrino RTOS
    qnx_ip=192.168.56.102
    curl -T build/x86-debug/flock_demo  ftp://qnxuser:qnxuser@$qnx_ip:/tmp/
    # trick to chmod binary without chmod command (missing on default BSP)
    curl  -Q "site chmod 0777 /tmp/flock_demo"  ftp://qnxuser:qnxuser@$qnx_ip

Now you can try on your QNX RTOS target:

/tmp/flock_demo /tmp/lock1

6324.186013936 Acquiring LOCK_EX on fd=3, fname='/tmp/lock1'
flock(fd=3, fname='/tmp/lock1', LOCK_EX): Function not implemented

Yes - it fails on /tmp/ which is RAM disk filesystem (intentionally limited) It is mentioned on RAM "filesystem" page.

Need to try other FS.

Building on Linux

You can use just this one-liner on Linux:

gcc -Wall -o /tmp/linux_flock_demo src/flock_demo.c 

The command should work on any Unix like fileystem on Linux:

/tmp/linux_flock_demo /tmp/lock1
6860.105908191 Acquiring LOCK_EX on fd=3, fname='/tmp/lock1'
6860.109659950 Acquired LOCK_EX on fd=3, fname='/tmp/lock1'
6860.110105333 Sleeping for 10 seconds...
6870.110866096 Releasing LOCK_EX on fd=3, fname='/tmp/lock1'
6870.110948286 Released LOCK_EX on fd=3, fname='/tmp/lock1'

While in sleep you can try run another instance of /tmp/linux_flock_demo to see LOCK_EX (exclusive) in action.

--hp

flock_demo's People

Contributors

hpaluch-pil avatar

Watchers

 avatar

Forkers

shiqinghui

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.