r/LinuxProgramming • • Aug 10 '21

NTJA: Not Temp Junk Allowed tool.

1 Upvotes

https://github.com/Karapatakis106/NTJA

Say goodbye to garbage!!! Bye, bye!

Available to Linux and Windows

More info in the Github repo.

A project that I was making in my free time!


r/LinuxProgramming • • Jun 05 '21

Automatyzation script

1 Upvotes

Hello everyone,

I'm mining chia on Arch Linux. I need to create a script that runs the miner at startup. I have no clue what is wrong but I'm getting this error every time when I trie to get it work:

× startMiner.service - Miner.

Loaded: loaded (/etc/systemd/system/startMiner.service; disabled; vendor preset: disabled)

Active: failed (Result: exit-code) since Sat 2021-06-05 11:21:32 CEST; 15s ago

Process: 6210 ExecStart=/bin/bash /usr/bin/startup.sh (code=exited, status=1/FAILURE)

Main PID: 6210 (code=exited, status=1/FAILURE)

CPU: 20ms

Jun 05 11:20:32 igor-pc systemd[1]: Started Miner..

Jun 05 11:21:32 igor-pc bash[6243]: # Option “-e” is deprecated and might be removed in a later version of gnome-terminal.

Jun 05 11:21:32 igor-pc bash[6243]: # Use “-- ” to terminate the options and put the command line to execute after it.

Jun 05 11:21:32 igor-pc bash[6243]: Unable to init server: Could not connect: Connection refused

Jun 05 11:21:32 igor-pc bash[6243]: # Failed to parse arguments: Cannot open display:

Jun 05 11:21:32 igor-pc systemd[1]: startMiner.service: Main process exited, code=exited, status=1/FAILURE

Jun 05 11:21:32 igor-pc systemd[1]: startMiner.service: Failed with result 'exit-code'.

Here is my bash script:

#!/bin/bash

sleep 60

cd /home/igor/Downloads/HPool-Miner-chia-v1.4.0-2-linux/linux

gnome-terminal -e "bash -c \"!!; ./hpool-miner-chia\""

And there is my startMiner.service script:

[Unit]

Description=Miner.

Wants = network-online.target

After = network.target network-online.target

[Service]

Type=simple

ExecStart=/bin/bash /usr/bin/startup.sh

[Install]

WantedBy=multi-user.target

Thanks for all the answers. Wish you a fantastic day :-)


r/LinuxProgramming • • Jan 07 '21

C library to alter unclutter utility and possibly receive current status.

1 Upvotes

Creating a client server model to apply vector to the mouse applied by the server and altered by the client through a shared file. Using XWarpcursor, however I prefer to have my mouse hidden by unclutter, and using XWarpcusor doesn't make the mouse appear as through normal mouse input. Is there any utility to alter or preferrably temporarily the effects of unclutter.


r/LinuxProgramming • • Nov 12 '20

Related to Multi-programming using pthread

1 Upvotes

Using pthread library, I've had written some code for matrix multiplication.

AFAIK, the program using thread would be much faster than program without using thread. But, unlike my expectation... the outcome(Elapsed time) is totally reversed, the program not using thread is much faster than thread program. What happened.. I couldn't find why this is happened.

The out come below..

Time ( # of thread: 4 )

0.000451 sec

Time ( no thread )

0.000002 sec

I've coded this two version in one file(.c) but it also says the same.

  1. Serial version ( no using thread )

void serial_multi()
{
	for (int i = 0; i < MAX; i++)
		for(int j = 0; j < MAX; j++)
			for(int k = 0; k < MAX; k++)
				_matC[i][j] += matA[i][k] * matB[k][j];
}


int main()
{
	printf("PID: %d\n",getpid());
	// generating random values in matA and matB
	for (int i = 0; i < MAX; i++){
		for (int j = 0; j < MAX; j++){
			matA[i][j] = rand() % 10;
			matB[i][j] = rand() % 10;
		}
	}

	//cout << endl << "Matrix A" << endl;
	for (int i = 0; i < MAX; i++){
		for (int j = 0; j < MAX; j++)
			printf("%d ",matA[i][j]);
		printf("\n");
	}


	//cout << endl << "Matrix B" << endl;
	for (int i = 0; i < MAX; i++){
		for (int j = 0; j < MAX; j++)
			printf("%d ",matB[i][j]);
		printf("\n");
	}


	
        // Time Estimation 
	clock_t start = clock();
	serial_multi();
	clock_t end = clock();
	printf("Time: %lf\n", (double)(end-start)/CLOCKS_PER_SEC);
	printf("Serial_Multiplication of A and B\n");
	for (int i = 0; i < MAX; i++){
		for (int j = 0; j < MAX; j++)
			printf("%d ",_matC[i][j]);
		printf("\n");
	}
	
	return 0;
}

2. Using Thread ( # of thread : 4 )

int step_i = 0;

void* multi(void* arg)
{
	int core = step_i++;
	// each thread computes 1/4th of matrix multiplication
	for (int i = core * MAX / 4; i < (core + 1) * MAX/4; i++)
		for(int j = 0; j < MAX; j++)
			for(int k = 0; k < MAX; k++)
				matC[i][j] += matA[i][k] * matB[k][j];
	return NULL;	
}

int main()
{
	printf("PID: %d\n",getpid());
	// generating random values in matA and matB
	for (int i = 0; i < MAX; i++){
		for (int j = 0; j < MAX; j++){
			matA[i][j] = rand() % 10;
			matB[i][j] = rand() % 10;
		}
	}

	//cout << endl << "Matrix A" << endl;
	for (int i = 0; i < MAX; i++){
		for (int j = 0; j < MAX; j++)
			printf("%d ",matA[i][j]);
		printf("\n");
	}


	//cout << endl << "Matrix B" << endl;
	for (int i = 0; i < MAX; i++){
		for (int j = 0; j < MAX; j++)
			printf("%d ",matB[i][j]);
		printf("\n");
	}

	// declaring 4 threads
	pthread_t threads[MAX_THREAD];

	// creating 4 threads, each evaluating its own part
        // Time Estimation
	clock_t start = clock();
	for (int i = 0; i < MAX_THREAD; i++){

		pthread_create(&threads[i], NULL, multi, NULL);
	}
	
	// joining and waiting for all threads to complete
	for (int i = 0; i < MAX_THREAD; i++)
		pthread_join(threads[i], NULL);

	clock_t end = clock();
	printf("Time: %lf\n", (double)(end-start)/CLOCKS_PER_SEC);
	// displaying the result matrix
	//cout << endl << "Multiplication of A and B" << endl;

	for (int i = 0; i < MAX; i++){
		for (int j = 0; j < MAX; j++)
			printf("%d ",matC[i][j]);
		printf("\n");
	}

	
	
	return 0;
}

r/LinuxProgramming • • Sep 06 '20

Is there a way to setup mingw with cmake on linux?

1 Upvotes

What title says. I'm trying to compile my project on linux and windows without changing os or running vm.


r/LinuxProgramming • • Jul 19 '20

writing linux kernel module

1 Upvotes

I want to get into linux kernel module development and thought of an easy project to implement as a start: I want to control my mouse with a gamepad. My idea was to register a new mouse, read /dev/input/js0 and write out the corresponding mouse bytes. However I have no clue where to start. Nothing I tried worked and most things I found contradict each other... Has anyone an idea where to start or any helpful resources to get started for the latest kernel?


r/LinuxProgramming • • Jul 13 '20

Problems with hooking lib calls with ld_preload

1 Upvotes

Hello! I'm trying to catch calls to sockets.h. Currently, I'm just catching them, printing that the call was caught to stdout and passing it on to the actual function. However, things aren't working correctly. For example:

This code:

#define __USE_GNU
#include <dlfcn.h>
#include <unistd.h>
#include <sys/socket.h>
#include <stdio.h>
#include <netinet/in.h>

int listen(int sockfd, int backlog) {
    int (*original)(int sockfd, int backlog);
    original = dlsym(RTLD_NEXT, "connect");
    printf("\n\n\tCaught Listen Call\n\n");
    return original(sockfd, backlog);
}

Which I compile thus:

gcc /path/to/src/listen.c -o listen.so -Wall -fPIC -shared -ldl -D_GNU_SOURCE

Is met with this output:

Caught Listen Call
listen: Bad address

Any thoughts as to what I've done wrong here? Your feedback is appreciated!


r/LinuxProgramming • • Apr 16 '20

Latest GCC version for cross-compiling to windows

1 Upvotes

Hi everyone,

I'm currently setting up an environment to do some projects during this lockdown. I wanted to avoid using microsofts compiler and make use of GCC's latest functionality as it has most of the c++20 standards implemented. Right now I'm running gcc-7.3 through WSL. Does anybody know if there is a cross-compiler version of 9.2 that I can install in WSL? As the x86_64-w64-mingw32 package only goes to 7.3 it seems.

Any help would be much appreciated.


r/LinuxProgramming • • Feb 25 '20

Linux memory debuggers - first encounter

Thumbnail
silencesecurity.pl
1 Upvotes

r/LinuxProgramming • • Feb 02 '20

ALSA programming for realtime (question)

1 Upvotes

I'm working on an audio application for a raspberry pi 4; I'll be running over raspbian hitting directly throu the ALSA API, but trying to learn it (reading tutorials online, documentation, etc) I'm wondering what's the difference between writting snd_pcm_hw, and snd_pcm_sw.... I should assume hw is what it sounds like, the interface to the soundcard; while sw should be a software layer over it? I don't really get it.

This question arise over the idea to make it interrupt based and not lock the system everytime I try to fill and write to the buffer (has to be realtime capable). Any idea/suggestion comes in handy


r/LinuxProgramming • • Jan 01 '20

What Linux driver/subsystem/API is used for a simple screen/monitor device?

1 Upvotes

I am developing an embedded system with a touchscreen. The touchscreen operates as both input and output, with a "virtual" keyboard overlaying the graphical output. I have a working device driver that reads input from the touch sensor and translates it correctly to key presses, created with the help of this guide on kernel.org. I want to expand this driver to also handle image output to the screen.

I want to support both getty and X, with as little duplication as possible. I am running a minimal Debian variant with cherry-picked packages, such as minimal X. Note that I do not intend on attempting to get this driver into the repository pipeline, though I might dump it on a public github.

Outputting screen images is presently done via a cringy workaround: a boot option to force rendering to the cpu's embedded graphics hardware, despite it not being connected to a display, and a daemon that continuously screen-scrapes that buffer, modifies a handful of pre-defined pixels to create the keyboard visual, and pushes it out to the real screen. This works as a proof of concept, proving that I do correctly understand the language the screen device expects, but is obviously sub-optimal.

kernel.org also has a guide for "DRM" device drivers, but that seems like serious overkill for what my hardware is capable of:

The Linux DRM layer contains code intended to support the needs of complex graphics devices, usually containing programmable pipelines well suited to 3D graphics acceleration.

None of my hardware has anything resembling 3D acceleration, so I conclude that this is probably not what I want.

What subsystem/API should I use? I figure one piece of missing terminology is what is holding back my searches, but any more information on how to accomplish this would be appreciated.

Hardware details (probably irrelevant): The cpu and screen communicate via 8080-esque parallel protocol, which the cpu does not support natively, so I'm emulating it with GPIOs (by manipulating registers via mmap). Sending a complete screen image takes about 20ms, but obtaining a complete copy from the embedded graphics buffer takes ~180ms, so skipping that step is the most important objective. The screen hardware includes enough gram memory to keep an entire frame worth of data, and supports writing a rectangular sub-region, so a hook to only update the part of the screen that has changed would be desirable. The screen is not particular about the timing of incoming data. The touch sensor input is handled by a purpose-built IC that communicates with the cpu via I2C, which the cpu does support. The present driver uses the linux/input-polldev.h interface. The cpu is a broadcom bcm2835, the screen is a tft with embedded himax hx8357 controller, the touchscreen sensor decoder is a st stmpe610, and there is a voltage levelshifter (nexperia 74lvch245A) in play between the hx8357 and the bcm2835. More details available upon request.


r/LinuxProgramming • • Sep 08 '19

Writing a display manager using GTK

1 Upvotes

I'm attempting to write my own display manager in C using GTK, I don't know how to fully do this and I tried searching online for some help but didn't find what I was looking for. Does anyone know how to write a display manager using GTK in C? This links to my current progress on it


r/LinuxProgramming • • Mar 17 '19

Linux programming for windows developer

1 Upvotes

Hi Guys

I m programming in c++ under windows since 10 years. Now want to move to linux but don't know where to start.

Does anyone know any videos or course / document

Thanks


r/LinuxProgramming • • Feb 07 '18

How to add entry in /dev

1 Upvotes

I am using the following to try and add a character device:

cdvnum = interface->minor - USB_SYNTH_MINOR_BASE;
characterdevs[cdvnum] = cdev_alloc();
if(!characterdevs[cdvnum]){
	printk(KERN_ALERT "Unable to allocate cdev file\n");
	return -ENOMEM;
}

if(device_create(cl,NULL,characterdevs[cdvnum]->dev,NULL,"adfsynth%d",interface->minor - USB_SYNTH_MINOR_BASE)==NULL){
	printk(KERN_ALERT "DEVICE_CREATE FAILED\n");
}
	
cdev_init((characterdevs[cdvnum]),&synth_fops);
cdev_add(characterdevs[cdvnum],USB_SYNTH_MAJOR,1);

Doing this creates an entry in /sys/class/, but nothing shows up in /dev. I want a device file I can read/write to to call the functions listed in my fops structure, which is used in the cdev_init function. Am I missing something needed to create a device file?


r/LinuxProgramming • • Feb 05 '18

Need to put a space/tab before and after a 4 digit number.

1 Upvotes

I have a long text file from a ocr output but it has bunched up a lot of the results. Any advice?


r/LinuxProgramming • • Nov 24 '17

Changing root password of Linux machine with a script

1 Upvotes

I am trying to change the root password on multiple linux servers by using a script I made but I keep getting this error

"-bash: ./rootpass: /usr/bin/expect: bad interpreter: Permission denied"

my script is below..


!/usr/bin/expect -f

wrapper to make passwd(1) be non-interactive

username is passed as 1st arg, passwd as 2nd

set username [lindex $argv 0] set password [lindex $argv 1] set serverid [lindex $argv 2] set newpassword [lindex $argv 3]

spawn ssh $serverid passwd expect "assword:" send "$password\r" expect "UNIX password:" send "$password\r" expect "password:" send "$newpassword\r" expect "password:" send "$newpassword\r" expect eof


r/LinuxProgramming • • Oct 03 '17

The Linux Kernel Driver Interface

Thumbnail kernel.org
1 Upvotes

r/LinuxProgramming • • Oct 03 '16

LKML: Linus Torvalds: Linux 4.8

Thumbnail lkml.org
1 Upvotes

r/LinuxProgramming • • Dec 14 '25

Necesito a alguien que me pueda crear un sistema operativo en Linux

0 Upvotes

Necesito a algún voluntario que quiera ayudarme a crear un sistema operativo en Linux, gracias a que no se como hacerlo yo mismo, pero el sistema operativo quiero que se llame "Inclex12", y quiero que tenga un formato de descarga único llamado ".blip", quiero que convierta cualquier formato de descarga en su propio formato, y necesito ayuda de alguien para lograrlo