23,716 questions
339
votes
4
answers
193k
views
When to wrap quotes around a shell variable?
Should or should I not wrap quotes around variables in a shell script?
For example, is the following correct:
xdg-open $URL
[ $? -eq 2 ]
or
xdg-open "$URL"
[ "$?" -eq "2"...
76
votes
1
answer
20k
views
What happens if you use the 32-bit int 0x80 Linux ABI in 64-bit code?
int 0x80 on Linux always invokes the 32-bit ABI, regardless of what mode it's called from: args in ebx, ecx, ... and syscall numbers from /usr/include/asm/unistd_32.h. (Or crashes on 64-bit kernels ...
52
votes
1
answer
22k
views
32-bit absolute addresses no longer allowed in x86-64 Linux?
64 bit Linux uses the small memory model by default, which puts all code and static data below the 2GB address limit. This makes sure that you can use 32-bit absolute addresses. Older versions of gcc ...
462
votes
11
answers
554k
views
How to terminate a python subprocess launched with shell=True
I'm launching a subprocess with the following command:
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
However, when I try to kill using:
p.terminate()
or
p.kill()
The command keeps ...
106
votes
8
answers
54k
views
How to avoid using printf in a signal handler?
Since printf is not reentrant, it's not supposed to be safe to use it in a signal handler. But I've seen lots of example codes that uses printf this way.
So my question is: when do we need to avoid ...
2199
votes
19
answers
3.0m
views
Looping through the content of a file in Bash
How do I iterate through each line of a text file with Bash?
With this script:
echo "Start!"
for p in (peptides.txt)
do
echo "${p}"
done
I get this output on the screen:
Start!
./runPep.sh: ...
144
votes
3
answers
101k
views
Why should eval be avoided in Bash, and what should I use instead?
Time and time again, I see Bash answers on Stack Overflow using eval and the answers get bashed, pun intended, for the use of such an "evil" construct. Why is eval so evil?
If eval can't be used ...
840
votes
33
answers
778k
views
Why can't I change directories using "cd" in a script?
I'm trying to write a small script to change the current directory to my project directory:
#!/bin/bash
cd /home/tree/projects/java
I saved this file as proj, added execute permission with chmod, and ...
14
votes
2
answers
4k
views
glibc scanf Segmentation faults when called from a function that doesn't align RSP
When compiling below code:
global main
extern printf, scanf
section .data
msg: db "Enter a number: ",10,0
format:db "%d",0
section .bss
number resb 4
section .text
main:
mov rdi, msg
...
219
votes
6
answers
114k
views
Java using much more memory than heap size (or size correctly Docker memory limit)
For my application, the memory used by the Java process is much more than the heap size.
The system where the containers are running starts to have memory problem because the container is taking much ...
14
votes
2
answers
18k
views
Facing an error "*** glibc detected *** free(): invalid next size (fast)"
Please see MSO question A long list of possible duplicates — C memory allocation and overrunning bounds for information about closely related questions.
Developer environment: CentOS 4.7, Kdevelop 3.1....
1112
votes
24
answers
2.2m
views
How to permanently set $PATH on Linux/Unix [closed]
On Linux, how can I add a directory to the $PATH so it remains persistent across different sessions?
Background
I'm trying to add a directory to my path so it will always be in my Linux path. I've ...
8
votes
2
answers
13k
views
How to control the source IP address of a ZeroMQ packet on a machine with multiple IPs?
The Python standard library's socket.create_connection()method has a source address option, for controlling which source IP a connection uses.
How do I do the same thing with a Python ZeroMQ socket,...
400
votes
9
answers
424k
views
How to use `subprocess` command with pipes
I want to use subprocess.check_output() with ps -A | grep 'process_name'.
I tried various solutions but so far nothing worked. Can someone guide me how to do it?
618
votes
7
answers
536k
views
How to keep environment variables when using sudo [closed]
When I use any command with sudo the environment variables are not there. For example after setting HTTP_PROXY the command wget works fine without sudo. However if I type sudo wget it says it can't ...
244
votes
16
answers
151k
views
Finding current executable's path without /proc/self/exe
It seems to me that Linux has it easy with /proc/self/exe. But I'd like to know if there is a convenient way to find the current application's directory in C/C++ with cross-platform interfaces. I've ...
181
votes
2
answers
578k
views
How to open, read, and write from serial port in C?
I am a little bit confused about reading and writing to a serial port. I have a USB device in Linux that uses the FTDI USB serial device converter driver. When I plug it in, it creates: /dev/ttyUSB1.
...
378
votes
22
answers
1.7m
views
Error: Could not find or load main class [duplicate]
I am having trouble compiling and running my Java code, intended to allow me to interface Java with a shared object for Vensim, a simulation modeling package.
The following code compiles without ...
908
votes
33
answers
1.0m
views
Argument list too long error for rm, cp, mv commands
I have several hundred PDFs under a directory in UNIX. The names of the PDFs are really long (approx. 60 chars).
When I try to delete all PDFs together using the following command:
rm -f *.pdf
I get ...
9
votes
2
answers
3k
views
Setting an argument with bash [duplicate]
I frequently run a simple bash command:
rpm -Uvh --define "_transaction_color 3" myPackage.rpm
which works properly.
But now I'm trying to script it into a bash file, and make it more flexible:
#!/...
183
votes
15
answers
249k
views
How to get CRON to call in the correct PATHs
I'm trying to get cron to call in the correct PATHs. When I run a Python script from shell the script runs fine as it uses the PATHs set in bashrc but when I use cron all the PATHs are not used from ...
1147
votes
15
answers
366k
views
How do I use sudo to redirect output to a location I don't have permission to write to? [closed]
I've been given sudo access on one of our development RedHat linux boxes, and I seem to find myself quite often needing to redirect output to a location I don't normally have write access to.
The ...
540
votes
30
answers
1.1m
views
How to fix 'sudo: no tty present and no askpass program specified' error?
I am trying to compile some sources using a makefile. In the makefile there is a bunch of commands that need to be ran as sudo.
When I compile the sources from a terminal all goes fine and the make ...
308
votes
18
answers
552k
views
Maximum number of threads per process in Linux?
What is the maximum number of threads that can be created by a process under Linux?
How (if possible) can this value be modified?
547
votes
16
answers
994k
views
Undefined reference to pthread_create in Linux
I picked up the following demo off the web from https://computing.llnl.gov/tutorials/pthreads/
#include <pthread.h>
#include <stdio.h>
#define NUM_THREADS 5
void *PrintHello(void *...