Block any Screen Recorder from recording desktop in Ubuntu

I am using Ubuntu 18.04
I want to make a program that can block screen recording.
I have tried 2 ways to achieve this

1. Using mandatory file lock in c++

#include <sys/file.h>
using namespace std;
int main(int argc,char **argv)
    int fd = open(argv[1], O_RDWR);
    static struct flock lock;
    lock.l_type = F_WRLCK;  //F_WRLCK   F_RDLCK
    lock.l_start = 0;
    lock.l_whence = SEEK_SET;
    lock.l_len = 0;
    lock.l_pid = getpid();
    cout<< fcntl(fd, F_SETLKW, &lock)<<'n';
    while (1) {      }  // to run this application so lock didn't release
    //will add release lock function here

    return 0;

I will lock the device file /dev/video0 which is used for the camera. In the same way I will lock the file which is used to record screen (currently I don’t know which device file used for screen recording).
This will keep the file locked so no other application can read from it.

2. Changing file permission
If i run
sudo chmod 002 /dev/snd (snd is responsible for audio)
It will change file permission to group write so no application can read data due to no permission.It will not play any audio and even videos which have audio.

Problem in both methods what i am facing

In 1st method
Somestimes files didn’t get locked and when it gets locked application can still read data from that.

In 2nd method
When I revert permission back to chmod 772 then the application is not able to read that change means they are not able to play any audio, to make that effect I have to reboot the system.

What needed to solve problem

In 1st method
After the file being got locked no process can read that device file.

In 2nd method
When I revert permission to 772, I don’t have to reboot for an application can read that effect. I should restart that audio process instead of PC.

Unix & Linux Asked on November 21, 2021

0 Answers

Add your own answers!

Related Questions

Authentication fails though the password is correct

0  Asked on September 3, 2020 by rohit-pillai


Cant’t load Windows 10 anymore

1  Asked on August 31, 2020 by j-doe


Change order a icons in system tray widget in KDE?

1  Asked on August 29, 2020 by paddy


rts5139/rtsx_usb borked in 3.15+

2  Asked on August 27, 2020 by roman


ETH0 no address ip with ifconfig

1  Asked on August 24, 2020 by akame14


Kali Linux 2020.2 Wifi Not Working (Realtek)

0  Asked on August 18, 2020 by harriet


Base64 encoded ignition file gets messed up

1  Asked on August 15, 2020 by michael-stbich


Weird textures on KDE Plasma 5.0

0  Asked on August 11, 2020 by rushisrinivas-k


How do I syntax check a Zsh script?

1  Asked on August 9, 2020 by akhil-jalagam


How can I swap my two screens, left to right?

5  Asked on August 4, 2020 by ripper234


Ask a Question

Get help from others!

© 2021 All rights reserved.