Category Archives: Linux

[Solved] Ubuntu Terminal Error: subprocess installed post-installation script returned error exit status 1

An error occurred in the ubuntu terminal:subprocess installed post-installation script returned error exit status 1
An error occurred in the ubuntu terminal:subprocess installed post-installation script returned error exit status 1

An error occurred in the ubuntu terminal:subprocess installed post-installation script returned error exit status 1

System: Ubuntu 16.04

Error:

Use Command cd /sur/bin/dpkg/info

Folder usage: ls | grep ubuntu-advantage-tools*

The command to find the file with the error uses:sudo rm ubuntu-advantage-tools*
Delete is OK!

Popen error: cannot allocate memory [How to Solve]

 

Foreword

This is a bug found in the actual project. After the device runs for a period of time, an error is reported: Poppen error: cannot allocate memory. Operating platform: Xintang nuc970, memory 64M, Linux kernel version: 3.10.108 +.


1. Popen introduction

The Popen function creates a child process to execute Shell, and shell A sub process is created to execute commands. From the practice process, it can be seen that after the process allocates memory and fills the process stack space, these functions fail to execute and return enomem error code cannot allocate memory. As long as the space is not released, the execution fails all the time

2. Cause analysis of Popen error

Here is a test program to reproduce the problem: the main thread malloc applies for heap space and fills the stack space of the process; Another thread performs the Popen operation. The result is that when the routine thread executes Popen, it always reports a Popen error: cannot allocate memory error until the main thread executes the free operation.

1. System memory of the device

2. Run the test program./test  , Max statck size is just 8m

3. Results: when the process is running, an error is reported when the heap space exceeds 8m, but in fact, the memory in the system is still sufficient, with more than 37m.

4. Once the space requested by malloc is released, it will return to normal immediately

5. Test program source code

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include <stdlib.h>
#include <sys/sysinfo.h>

#define SIZE (1024*1024*1)
#define MEM_SIZE (45)

void *routine(void *arg)
{
	struct sysinfo info;
	
	while(1)
	{		
		sysinfo(&info);
		printf("freeram = %ld\n",info.freeram);
		
		FILE* fp = popen("cat /sys/class/net/eth0/carrier", "r");
		if(fp == NULL)
		{
			printf("popen error:%s\n", strerror(errno));
			sleep(1);
			continue;
		}
		
		char  buffer[1024];
		int   bytes_read = fread(buffer, 1, sizeof(buffer), fp);
		pclose(fp);

		printf("popen ok %2x\n",buffer[0]);			
		sleep(1);
		
	}
}

int main(int argc, char **argv)
{
		
	pthread_t tid;
	pthread_create(&tid, NULL, routine, NULL);
	

	unsigned int *p = (unsigned int *)malloc(1024 * 1024 * MEM_SIZE);
	printf("malloc buffer: %p\n", p);

	for (int i = 0; i < 1024 * 1024 * (MEM_SIZE/sizeof(int)); i++) 
	{
		p[i] = 123;
		if ((i & 0xFFFFF) == 0) 
		{
			printf("%dMB written\n", i >> 18);
			sleep(1);
			//usleep(100000);
		}

	}

	
	while(1)
	{
		sleep(20);
		if(p)
		{
			printf("free mem\n"); //The popen call is normal after the memory is released
			free(p);
			p = NULL;
		}
	}
	
	return 0;
}

Summary

The system overhead of functions such as Popen is very high. When the process memory is tight, it is easy to make mistakes. If the requested memory space is not released in time, the execution fails all the time.

ERROR: configuration failed for package ‘openssl’ [How to Solve]

ERROR: configuration failed for package ‘openssl’
removing ‘/usr/local/lib/R/site-library/openssl’
The ubuntu system lacks openssl:

apt-get install openssl
apt-get install openssl-devel

Or:

wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz

tar -xvf  openssl-1.1.1i.tar.gz

cd openssl-1.1.1i/

./config 

make && make install

./config shared 

make clean

make  && make install

[Solved] C++: fatal error: Killed signal terminated program cc1plus

[problem solving] C + +: fatal error: killed signal terminated program cc1plus

1. Problem description

During C + + compilation in Linux system, the following errors occur, resulting in compilation abort:

C++: fatal error: Killed signal terminated program cc1plus
compilation terminated.

2. Solution – swap partition

After consulting the relevant information, it is considered that the virtual machine is caused by insufficient memory. This problem is solved by creating swap partition, and the compilation is successful
the following is a summary of the creation and activation of swap partitions:

# Create the partition path
sudo mkdir -p /var/cache/swap/
# Set the size of the partition
# bs=64M is the block size, count=64 is the number of blocks, so the swap space size is bs*count=4096MB=4GB
sudo dd if=/dev/zero of=/var/cache/swap/swap0 bs=64M count=64
# Set permissions for this directory
sudo chmod 0600 /var/cache/swap/swap0
# Create the SWAP file
sudo mkswap /var/cache/swap/swap0
# Activate the SWAP file
sudo swapon /var/cache/swap/swap0
# Check if SWAP information is correct
sudo swapon -s

The effect diagram of partition creation and activation is as follows:

The path of the swap 0 file is under/var/cache/swap/. After compilation, if you don’t want to swap partitions, you can delete it.

Command to delete swap partition:

sudo swapoff /var/cache/swap/swap0
sudo rm /var/cache/swap/swap0

Free space command:

sudo swapoff -a
#Detailed usage: swapoff --help
#View current memory usage: --swapoff: free -m

[Solved] Flask Error: RuntimeError: The session is unavailable because no secret key was set.

RuntimeError: The session is unavailable because no secret key was set. Set the secret_ key on the application to something unique and secret.

When we run the flash project on the Linux system, we encounter this error:

Solution:

Basically, on the Internet, you can set secret under the flash object app_ Key:
if it is added to the startup file of my project, I can successfully run the project under windows10. If it cannot succeed on the Linux system, it still reports an error

if it is added to the startup file of my project, it can run successfully on Linux

[docker][issue]Error response from daemon: mkdir xxx: file exists: unknown

Problem Description:
after the docker is closed abnormally, the following error is reported when starting the container:

linux> Error response from daemon: mkdir /run/containerd/io.containerd.runtime.v1.linux/moby/189aafa489967asdf23664d32f9e33e121a7b3b6e789d8642345678dfg6ebe13cb: file exists: unknown
linux> Error: failed to start containers: asdf

Solution:

# excute
linux> ps aux | grep 189aafa489967asdf23664d32f9e33e121a7b3b6e789d8642345678dfg6ebe13cb
# output
linux> root      6358  0.0  0.0 108748  4136 ?       Sl   Oct27   1:50 containerd-shim -namespace moby -workdir /var/lib/containerd/io.containerd.runtime.v1.linux/moby/189aafa489967asdf23664d32f9e33e121a7b3b6e789d8642345678dfg6ebe13cb -address /run/containerd/containerd.sock -containerd-binary /usr/bin/containerd -runtime-root /var/run/docker/runtime-nvidia
# Kill off and restart the container
kill 6358

[Solved] GCC Compile Error: fatal error: sys/cdefs.h: No such file or directory

Question:

/usr/include/features.h:367:25: fatal error: sys/cdefs.h: No such file or directory

analysis:

Error in compiling 32-bit program on 64 bit host (- M32 option), install the necessary software package;

Solution:

$ sudo apt install gcc-multilib 	# Generally you can install this, if you can't install the following
$ sudo apt install g++-multilib
$ sudo apt install libc6-dev libc6-dev-i386

Parse error in ubantu/Linux system [How to Solve]

Parse error in ubantu/Linux system

This problem took me some time. In order to avoid forgetting to post a blog in the future

Phenomenon:

The execution code and error reporting contents are as follows:

reason:

This is because the standard supported by the Linux gcc compiler is different from the current C89 standard. This C standard requires that the declaration of variables in a block be placed in front of all non declarative statements.

We can see that on line 266, a definition statement is placed before the declaration statement, so an error is reported

Solution:

Put 266 this non declarative statement under all declarative statements
as shown in the following figure:

the compilation succeeded without error, and the problem was solved successfully

[Solved] YUM Error: error: rpmdb: BDB0113 Thread/process 11498/140107732375616 failed

Problem description

An error occurred while installing the software using yum

[root@localhost ~]# yum install pv -y
error: rpmdb: BDB0113 Thread/process 11498/140107732375616 failed: BDB1507 Thread died in Berkeley DB library
error: db5 error(-30973) from dbenv->failchk: BDB0087 DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db5 -  (-30973)
error: cannot open Packages database in /var/lib/rpm
CRITICAL:yum.main:

Error: rpmdb open failed
[root@localhost ~]# 

Problem analysis

Yum was unable to open the package index using db5 – (- 30973) and the package database in/var/lib/rpm
according to the prompt yumrpmdb: bdb0113 thread/process 11498/140107732375616 failed, enter/var/lib/rpm to delete the corresponding DB file, and then rebuild yum

Solution:

1. View the/var/lib/RPM directory and delete it__DB * file

$ /var/lib/rpm
$ ls
Basenames     __db.001  __db.003  Group       Name          Packages     Requirename  Sigmd5
Conflictname  __db.002  Dirnames  Installtid  Obsoletename  Providename  Sha1header   Triggername
$ rm -rf __db.*

2. Refactoring yum

$ rpm --rebuilddb

3. Clear Yum cache

$ yum clean all

4. Update the software chain of Yum

$  yum repolist

[Solved] Ubuntu Error: Failed to connect to 127.0.0.1 port xxxxx: Connection refused

Method 1

Check the agent

git config --global http.proxy
git config --global https.proxy

Cancel if you have one, or change another method if you don’t

git config --global --unset http.proxy
git config --global --unset https.proxy

Method 2

Check whether the system environment uses agents

env|grep -I proxy

The following similar configuration appears

If there is a corresponding agent, cancel it

unset http_proxy
unset https_proxy

Method 3

Manually operate the Ubuntu agent and cancel the agent in the settings.

[Solved] RHEL 7 installs Oracle RAC 11.2.0.4, executes root.sh error ohasd: failed to start

RHEL 7 installs Oracle RAC 11.2.0.4, executes root.sh and reports an error ohasd failed to start

Error reporting reason:

Because RHEL 7 uses SYSTEMd instead of initd to run and restart processes, while root.sh runs ohad processes through traditional initd.

Solution:
in RHEL 7, ohasd needs to be set as a service before running the script root.sh
the steps are as follows:

1. Create service file as root user
[root@rac1 ~]# touch /usr/lib/systemd/system/ohas.service
[root@rac1 ~]# chmod 777 /usr/lib/systemd/system/ohas.service
2. Add the following to the newly created ohas.service file
[root@rac1 init.d]# cat /usr/lib/systemd/system/ohas.service
[Unit]
Description=Oracle High Availability Services
After=syslog.target

[Service]
ExecStart=/etc/init.d/init.ohasd run >/dev/null 2>&1 Type=simple
Restart=always

[Install]
WantedBy=multi-user.target

3. Run the following command as root user
systemctl daemon-reload
systemctl enable ohas.service
systemctl start ohas.service
4. View running status
[root@rac1 init.d]# systemctl status ohas.service

Run root.sh after the service is up
if the ohad failed to start error is still reported, it may be that ohas.service does not start immediately after init.ohad is created by the root.sh script. Refer to the following for solutions:

When running root.sh, refresh/etc/init. D until the init.ohasd file appears. Start ohas.service manually immediately. The service command is systemctl start ohas.service