date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,453,743,545,000
General problem I want to write a script that interacts with the user even though it is in the middle of a chain of pipes. Concrete example Concretely, it takes a file or stdin, displays lines (with line numbers), asks the user to input a selection or line numbers, and then prints the corresponding lines to stdout. Le...
Using /proc/$PPID/fd/0 is unreliable: the parent of the selector process may not have the terminal as its input. There is a standard path that always refers to the current process's terminal: /dev/tty. nl "$INPUT" >/dev/tty read -p"Select options: " </dev/tty or exec </dev/tty >/dev/tty nl "$INPUT" read -p"Select opt...
How to read user input when using script in pipe
1,453,743,545,000
I'm investigating the behaviour of a script that is normally run as an automated process (e.g. cron, Jenkins). The script can (eventually) invoke commands that behave differently (seeking user input) when run interactively; for example, patch will ask what to do with a reversed patch, and svn will ask for passwords, ...
You need to start another session not attached to a terminal, so for instance: $ setsid sh -c 'tty; ps -jp "$$"; echo test' < /dev/null > log 2>&1 $ cat log not a tty PID PGID SID TTY TIME CMD 19506 19506 19506 ? 00:00:00 sh test See also the start-stop-daemon command found on some Linux distribu...
Invoke a command/script disconnected from the controlling terminal?
1,453,743,545,000
I have a number of functions defined in my .bashrc, intented to be used interactively in a terminal. I generally preceded them with a comment describing its intended usage: # Usage: foo [bar] # Foo's a bar into a baz foo() { ... } This is fine if browsing the source code, but it's nice to run type in the terminal ...
I don't think that there is just one good way to do this. Many functions, scripts, and other executables provide a help message if the user provides -h or --help as an option: $ foo() { [[ "$1" =~ (-h|--help) ]] && { cat <<EOF Usage: foo [bar] Foo's a bar into a baz EOF return; } : ...other stuff... } For example: $ ...
Displaying usage comments in functions intended to be used interactively
1,453,743,545,000
I have written some scripts and stored them in my ~/bin folder. I'm already able to run them just by calling their title during a shell session. However, they aren't running interactively (I mean, my ~/.bashrc aliases are not loaded). Is there a way to mark them to run interactively by default? Or must I source ~/.bas...
If you add the -i option to your hashbang(s) it will specify that the script runs in interactive mode. #!/bin/bash -i Alternatively you could call the scripts with that option: bash -i /path/to/script.sh
Is possible to define a bash script to run interactively by default?
1,453,743,545,000
I often want a temporary directly where I can unpack some archive (or create a temporary project), see around some files. It is unpredictable in advance for how much time a particular directory may be needed. Such directories are often clutter home directory, /tmp, project directories. They often have names like some ...
It doesn’t quite cover all the features you mention (easily making the temporary directory persistent), but I rather like Kusalananda’s shell for this. It creates a temporary directory, starts a new shell inside it and cleans the temporary directory up when the shell exits. Before the shell exits, if you decide you wa...
Is there some interactive analogue of `mktemp` that helps to organize throw-away directories?
1,453,743,545,000
I'm writing a pretty ad-hoc install script for some thing. No much control constructs, basically just a list of commands. I'd like the user to confirm each command before it gets executed. Is there a way to let bash do that, without prefixing every command with a shell function name?
You could use extdebug: shopt -s extdebug trap ' IFS= read -rn1 -d '' -p "run \"$BASH_COMMAND\"? " answer <> /dev/tty 1>&0 echo > /dev/tty [[ $answer = [yY] ]]' DEBUG cmd1 cmd2 ... For reference, the zsh equivalent would be: TRAPDEBUG() { read -q "?run \"$ZSH_DEBUG_CMD\"? " || setopt errexit echo > /dev/tt...
Prompt for confirmation for every command
1,453,743,545,000
I am writing a shell script to install all my required applications on my Ubuntu PC in one shot (while I can take a stroll or do something else). For most applications adding -y to the end of the apt-get install statement, has worked well to avoid the need for any user involvement. My script looks something like this:...
Configure the debconf database: echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections Then, install Wireshark: sudo DEBIAN_FRONTEND=noninteractive apt-get -y install wireshark You might also want to suppress the output of apt-get. In that case: sudo DEBIAN_FRONTEND=nonint...
How to choose a response for interactive prompt during installation from a shell script
1,453,743,545,000
From what I understanding, a daemon is a background process, but daemon requires unique config file to set the environment variable. E.g. Hadoop daemon require hadoop-env.sh to set environment variable JAVA_HOME, you can't simply get the variable from ~/.bashrc. The reason is because of daemon as a background proces...
You already have the opportunity to set BASH_ENV to the pathname of a file that non-interactive shell script parse before running. This allows you to do, in a crontab for example @hourly BASH_ENV="$HOME/.bashrc_non_interactive" "$HOME/bin/mybashscript" or even BASH_ENV="$HOME/.bashrc_non_interactive" @hourly "$HOME/...
Why no such non-interactive version of bashrc?
1,453,743,545,000
Updated: This is not a file system problem. I used to be able to enter: $ echo kødpålæg But now bash/zsh change this to: bash$ echo kddddddddplg zsh$ echo k<c3><b8>dp<c3><a5>l<c3><a6>g I can run cat and enter 'kødpålæg' with no problem: $ cat kødpålæg kødpålæg This is both with this environment: $ locale LANG=C ...
I'd say most likely your terminal is misconfigured and sends and displays characters in some single-byte character set, probably ISO8859-1 or ISO8859-15 given the sample characters you show instead of the locale's charset. There is typically no ø, å, æ character in the C locale and the ISO8859-1(5) encoding of those c...
Non-ascii chars are no longer displayed in bash
1,453,743,545,000
Such as in a bash script: read -p "Only UI(y/n)" Temp_Answer.  Is it possible to do this while a Makefile is running? Because I want to do different things based on the $Temp_Answer (Y or N) in Makefile.
Accessing shell variables All exported shell environment variables are accessible like so: $(MYBASEDIR) Example Say I have this Makefile. $ cat Makefile all: @echo $(FOO) Now with no variable set, big surprise, we get nothing: $ printenv | grep FOO $ $ make $ With the variable just set, but not exported: $ ...
How to get variables from the command line while makefile is runing?
1,453,743,545,000
I'm trying to figure out what words does the -interactive option of cp accepts as input. For your convenience, here's code that sets up files for experimentation. touch example_file{1..3} mkdir example_dir cp example_file? example_dir cp -i example_file? example_dir The shell then asks interactively for each file whe...
The POSIX standard only specifies that the response need to be "affirmative" for the copying to be carried out when -i is in effect. For GNU cp, the actual input at that point is handled by a function called yesno(). This function is defined in the lib/yesno.c file in the gnulib source distribution, and looks like th...
Copying files interactively: "cp: overwrite"
1,453,743,545,000
I use the following code as part of a much larger script: mysql -u root -p << MYSQL create user '${DOMAIN}'@'localhost' identified by '${DOMAIN}'; create database ${DOMAIN}; GRANT ALL PRIVILEGES ON ${DOMAIN}.* TO ${domain}@localhost; MYSQL As you can see it creates an authorized, allprivileged DB user, an...
Just have the user store the variable beforehand with read: echo "Please enter password for user ${domain}: "; read -s psw mysql -u root -p << MYSQL create user '${domain}'@'localhost' identified by '${psw}'; create database ${domain}; GRANT ALL PRIVILEGES ON ${domain}.* TO ${domain}@localhost; MYSQL Here, the...
Making mysql CLI ask me for a password interactively
1,453,743,545,000
I'm trying to bring up a terminal to interactively ask for a file, and open it using a GUI program: foot /bin/sh -c 'file=`fzf`;(setsid xdg-open "$file" &)' I'm using setsid, because otherwise the terminal takes down the xdg-open with it when it exits. The command above, however, doesn't work: it still exits without ...
The background process: detaches from the terminal (setsid); runs xdg-open. If the terminal disappears before step 1 is finished, the whole process group receives a SIGHUP and is killed. setsid prevents the SIGHUP from reaching xdg-open, but that doesn't help if setsid (or the subshell working to invoke setsid) is k...
Running a program outside of terminal
1,453,743,545,000
On my source REDHAT Linux 7 host i fire this command to never prompt for password and passwordless login ssh -i /app/axmw/ssh_keys/id_rsa -o PasswordAuthentication=no root@<target-host> -vvv This works for a list of host and I can determine if ssh is working or not non-interactively [with no password prompt]. However...
debug1: Next authentication method: keyboard-interactive You're being prompted for "keyboard-interactive" authentication, which is technically separate from "password" authentication. Keyboard-interactive is like password, but the server provides the prompt message. It's often used with things like RSA tokens and yub...
PasswordAuthentication=no flag does not work on one strange host
1,453,743,545,000
I'm using tcsh, and have to source a group .cshrc file. This file echoes some messages, which is fine for normal shells, but causes problems with programs like scp and rsync. I can see the solution taking one of a few forms, but am unable to implement any of them. Only execute echos when appropriate I've scoured the r...
The idiom I use is if ( $?prompt ) then # interactive commands here endif note that it's spelled $prompt (lowercase), not $PROMPT. % echo $prompt %U%m%u:%B%~%b%# % ssh localhost 'echo $prompt' Warning: Permanently added 'localhost' (RSA) to the list of known hosts. Password: prompt: Undefined variable. If $pro...
Supress startup messages on stdout?
1,453,743,545,000
I have been doing this for a while: sudo su - but it uses 'sh' rather than 'bash', which is what I'd like to do. Which command will log me in as root and get me a bash shell even if that's not the default the system gives me?
Try this command: sudo -i bash
On OS X, how do I log in interactively as root starting from my normal user account?
1,453,743,545,000
I want to count number of interactively removed files and directories: for f in /tmp/mydir/* ; do rm -ir "$f" done How to do it in most concise/elegant way? Example: abc@def:/tmp/mydir$ tree . ├── 1 ├── 2 ├── 3 ├── 4 ├── A │   ├── 1 │   ├── 2 │   └── 3 ├── B │   ├── 1 │   └── 2 └── C 3 directories, 9 files If al...
simply use: rm -vri files | wc -l will include dirs, too (i.e. the removal of A). This will work as -v will only send successful removed ’file’ (or dir) output to stdout, while all others go to stderr. In your example the output will be 12, as there are 3 dirs and 9 files.
Count deleted files with interactive rm (rm -i)
1,453,743,545,000
I have to convert multiple video files in a folder. I have to rename each one of them but I need the script to prompt me to write a custom name for each filename. Here is what I've got so far: First I need to remove the filename spaces which my script does with that command: for f in *' '*; do mv "$f" "`echo $f | sed...
Just use read to read one line from STDIN, like this. for FILE in *; do echo "Rename '$FILE' to:" read NAME mv "$FILE" "$NAME" done This example would require you to press Ctrl-C to abort when you're done, but you could add an extra if case to abort e.g. if no name was entered. EDIT: If you want all your ...
For loop for renaming files with prompt for each filename
1,453,743,545,000
I have read the following in this question: A shell running a script is always a non-interactive shell, but the script can emulate an interactive shell by prompting the user to input values. I don't know if the above statement is correct, I thought the following is correct: A shell running a script and this scr...
A shell running a script is a non-interactive shell. A non-interactive shell can still use e.g. read to read data from standard input. If standard input is a terminal, this may provide a level of "interaction", but it does not make the shell executing the script an interactive shell. Thu script will be "interactive" ...
Confused about the meaning of an interactive and non-interactive shell when running a script
1,453,743,545,000
Is there a simple way to let the user interactively choose one of the lines of the output of lsblk -f? NAME FSTYPE LABEL MOUNTPOINT sda ├─sda1 ntfs WINRE_DRV ├─sda2 vfat SYSTEM_DRV ├─sda3 vfat LRS_ESP ├─sda4 ├─sda5 ntfs Windows8_OS /med...
You're looking for dialog. It's a very powerful tool and uses ncurses to provide a lot of options. I suggest you read through its manpage. Specifically, you want the --menu option: --menu text height width menu-height [ tag item ] ... As its name suggests, a menu box is a dialog box that can be ...
Interactive multiple choice in a bash script
1,453,743,545,000
Specifically Up/Down for history navigation. What I already know I understand dash is a minimalistic, no bloat, (somewhat) strict POSIX shell. I understand the philosophy behind it, and the reason features, that have become basic in other interactive shells, are not present in dash. I've looked into the following reso...
I ran into this problem on macOS and ended up finding that the simplest option was to use rlwrap (https://github.com/hanslub42/rlwrap). In my particular case, in iTerm, I set up a profile for dash with the following command to execute it whenever I want to use the dash shell (-l is for login mode; -E is for emacs comm...
Anyway to bind keyboard to dash (Debian Almquist Shell)?
1,453,743,545,000
Is there a way for setting an environment variable in bash such that its value is not passed directly after = but is prompted for separately? For example, something akin to $ TEST=< (syntax does not actually work) instead of $ TEST=test.
As Stephen answered in the comments, shells that adhere to the POSIX spec will have a way to read input into a variable. bash includes several extra flag to the read built-in command, none of which you need for your situation: read TEST will leave your terminal waiting for you to enter a line of input, which will be ...
Setting environment variables by prompt instead of in command line
1,453,743,545,000
I'm piping output of an interactive command (ghci) through sed-based script to add some colors: ghci | colorize.sh where colorize.sh is something like: #!/bin/bash trap '' INT sed '...some pattern...' Now if I hit Ctrl-C I want only ghci to receive it (it does not terminate), and I want sed to thrive (or perhaps get...
First, let me start out by saying that this doesn't answer your question, but I hope might help clarify what's happening. I suspect that what you think is happening might not really be happening. Consider this simple example: # The 'writer' reads input from standard input and # echos it to standard output. It handl...
How to trap INT signal infinitely many times?
1,453,743,545,000
I want the color of my zsh prompt to be decided based on whether I'm inside a tmux session or not. In bash, it can be done by checking the value of $TMUX, but I can't find an equivalent method in zsh. Is it possible in zsh?
In zsh, the prompt_subst option is off by default. If you want to use variable substitutions in your prompt, turn it on. setopt prompt_subst PS1='$foo' For $TMUX, though, you don't need this. The value doesn't change during the session, so you can initialize PS1 when the shell starts. setopt prompt_subst if (($+TMUX)...
Format zsh prompt according to the value of an environment variable
1,453,743,545,000
A lot of my workflow involves using a sudo interactive session (sudo -i) as a service user that is able to run certain things that my personal username can't. When I do this, I like to preserve my PS1 variable and some other little bash niceties. As I can't modify the service user's .bashrc, I have a script set up in ...
You could use --rcfile to tell bash to read your ps1.sh file instead of the service_user's .bashrc: sudo -i -u service_user bash --rcfile /home/me/ps1.sh The execution flow then will be something like sudo running bash -lc 'bash --rcfile /home/me/ps1.sh' as service_user. If you want to source the service_user's .bas...
Is it possible to begin a sudo interactive session and also provide an initial command?
1,453,743,545,000
I'm looking for a command that invokes readline or similar, primed with the current $PWD, to let the user edit the current directory, then cd to the edited value. E.g. > cd ~/a/b/c/d > pwd > /home/alice/a/b/c/d Then run the proposed icd command (for "interactive cd", inspired by imv in renameutils). It prompts the u...
For bash and any other shell supporting readline you might be able to use this function icd() { local a; read -ei "${1:-$PWD}" -p "$FUNCNAME> " a && cd "$a"; } Usage icd # Starts editing with $PWD icd /root # Starts editing with /root
sh: is there a command to interactively edit the PWD?
1,453,743,545,000
I only want to determine from my POSIX shell script, if it is running interactively, but for some reason, the following function: running_interactively() { printf '%s' ${-} | grep -F i > /dev/null 2>&1 } returns false even if I run the script in terminal. Am I doing it wrong, or is the definition of interactive s...
A shell script is, unless it's sourced by an interactive shell, very seldom run in an interactive shell environment. This means that $- would not include an i. What you could check is to see whether standard input is connected to a terminal or not. This is done using the -t test with an argument of 0 (the file descr...
Confused about determining if a shell script is running interactively
1,453,743,545,000
Here is my loop ls -ltrd * | head -n -3 | awk '{print $NF}' | while read y; do rm -iR $y done output: rm: descend into directory oct_temp17? rm: descend into directory oct_temp18? rm: descend into directory oct_temp19? .... It does not prompt for user confirmation which rm -i should ideally when run manually....
1. Why you example did not work as expected rm's prompts need STDIN to receive your feedback. In your example you used STDIN to pipe a list to the while loop though, thus rm was getting the answers to it's prompts from your ls/head/awk commands, instead of the user. The solution is to not use STDIN for providing the l...
rm -iR does not work inside a loop
1,345,896,409,000
Is there such a thing as list of available D-Bus services? I've stumbled upon a few, like those provided by NetworkManager, Rhythmbox, Skype, HAL. I wonder if I can find a rather complete list of provided services/interfaces.
On QT setups (short commands and clean, human readable output) you can run: qdbus will list list the services available on the session bus and qdbus --system will list list the services available on the system bus. On any setup you can use dbus-send dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesk...
A list of available D-Bus services
1,345,896,409,000
I heard that FIFOs are named pipes. And they have exactly the same semantics. On the other hand, I think Unix domain socket is quite similar to pipe (although I've never made use of it). So I wonder if they all refer to the same implementation in Linux kernel. Any idea?
UNIX domain sockets and FIFO may share some part of their implementation but they are conceptually very different. FIFO functions at a very low level. One process writes bytes into the pipe and another one reads from it. A UNIX domain socket has similar behaviour as a TCP/IP or UDP/IP socket. A socket is bidirectional...
Are FIFO, pipe & Unix domain socket the same thing in Linux kernel?
1,345,896,409,000
This is a follow-up question to A list of available DBus services. The following python code will list all available DBus services. import dbus for service in dbus.SystemBus().list_names(): print(service) How do we list out the object paths under the services in python? It is ok if the answer does not involve pyt...
QT setups provide the most convenient way to do it, via qdbus: qdbus --system org.freedesktop.UPower prints / /org /org/freedesktop /org/freedesktop/UPower /org/freedesktop/UPower/Wakeups /org/freedesktop/UPower/devices /org/freedesktop/UPower/devices/line_power_ADP0 /org/freedesktop/UPower/devices/DisplayDevice /org...
How to list all object paths under a dbus service?
1,345,896,409,000
We can check the details of system V message queue with the help of ipcscommand. Is there any command to check POSIX message queue in Linux?
There is no command I know of but there exists a libc function call which can get the statistics: man 3 mq_getattr mq_getattr() returns an mq_attr structure in the buffer pointed by attr. This structure is defined as: struct mq_attr { long mq_flags; /* Flags: 0 or O_NONBLOCK */ ...
linux command to check POSIX message queue
1,345,896,409,000
Passing a password on command line (to a child process started from my program) is known to be insecure (because it can be seen even by other users with ps command). Is it OK to pass it as an environment variable instead? What else can I use to pass it? (Except of environment variable) the easiest solution seems to us...
Process arguments are visible to all users, but the environment is only visible to the same user (at least on Linux, and I think on every modern unix variant). So passing a password through an environment variable is safe. If someone can read your environment variables, they can execute processes as you, so it's game ...
How to pass a password to a child process?
1,345,896,409,000
For intercepting/analyzing network traffic, we have a utility called Wireshark. Do we have a similar utility for intercepting all the interprocess communication between any two processes in Unix/Linux? I have created some processes in memory and I need to profile how they communicate with each other.
This depends a lot on the communication mechanism. At the most transparent end of the spectrum, processes can communicate using internet sockets (i.e. IP). Then wireshark or tcpdump can show all traffic by pointing it at the loopback interface. At an intermediate level, traffic on pipes and unix sockets can be obser...
Is there a way to intercept interprocess communication in Unix/Linux?
1,345,896,409,000
In the list of signals defined in a linux system, there are two signals stated as User Defined signals (SIGUSR1 and SIGUSR2). Other signals will be raised or caught in specific situations, but SIGUSRs are left for user application's use. So why only two signals?
Historically, Unix had only these two signals, but modern systems have the real-time signals SIGRTMIN...SIGRTMAX. Due to the wacky and unportable semantics of the signal APIs, there is almost no use case where signals would be preferrable over other communication mechanisms like pipes. Therefore, allocating a new sign...
Why there are only two user defined signals?
1,345,896,409,000
When using a MySQL client (e.g. mysql) how can I determine whether it connected to the server using a Unix socket file or by using TCP/IP?
Finding the transport Try using netstat -ln | grep 'mysql' and you can see how it is connected by the output. if you have access to shell On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to ...
How can I determine the connection method used by a MySQL client?
1,345,896,409,000
The special variable $RANDOM has a new value every time it's accessed. In this respect, it is reminiscent of the "generator" objects found in some languages. Is there a way to implement something like this in zsh? I tried to do this with named pipes, but I did not find a way to extract items from the fifo in a contro...
ksh93 has disciplines which are typically used for this kind of thing. With zsh, you could hijack the dynamic named directory feature: Define for instance: zsh_directory_name() { case $1 in (n) case $2 in (incr) reply=($((++incr))) esac esac } And then you can use ~[incr] to get an increme...
How to implement "generators" like $RANDOM?
1,345,896,409,000
As far as I understood one end of a pipe has both read and write fd's and the other end also has read and write fd's. Thats why when we are writing using fd[1], we are closing the read end e.g. fd[0] of the same side of the pipe and when we are reading from the 2nd end using fd[0] we close the fd[1] of that end. A...
Yes, a pipe made with pipe() has two file descriptors. fd[0] for reading and fd[1] for writing. No, you do not have to close either end of the pipe, it can be used for bidirectional communication. Edit: in the comments you want to know how this relates to ls | less, so I'll explain that too: Your shell has three open ...
Does one end of a pipe have both read and write fd?
1,345,896,409,000
In a Debian lenny server running postgresql, I noticed that a lack of semaphore arrays is preventing Apache from starting up. Looking at the limits, I see 128 arrays used out of 128 arrays maximum, for semaphores. I know this is the problem because it happens on a semget call. How do I increase the number of arrays? P...
If you read the manpage for semget, in the Notes section you'll notice: System wide maximum number of semaphore sets: policy dependent (on Linux, this limit can be read and modified via the fourth field of /proc/sys/kernel/sem). On my system, cat /proc/sys/kernel/sem reports: 250 32000 32 128 So do that on your ...
How do I increase the number of semaphore arrays in Linux?
1,345,896,409,000
Is there a way of implementing the publish / subscribe pattern from the command line without using a server process? This need only work on one machine. The main thing I want to avoid by not having a server process is having configure a machine to use these tools. I'm also quite keen on not having to deal with the pos...
All subscribers need to be notified of new data in a way that doesn't affect other subscribers and the server must not have to keep track of what data subscribers have received. This makes FIFO useless for this purpose. Ironically a regular file will do exactly what you want because file descriptors on regular files k...
Command line pub / sub without a server?
1,345,896,409,000
I'm trying to access a process' stdio streams from outside its parent process. I've found the /proc/[pid]/fd directory, but when I try $ cat /proc/[pid]/fd/1 I get a No such file or device error. I know for certain that it exists, as Dolphin (file explorer) shows it. I also happened to notice the file explorer lists ...
tl;dr; As of 2020, you cannot do that (or anything similar) if /proc/<pid>/fd/<fd> is a socket. The stdin, stdout, stderr of a process may be any kind of file, not necessarily pipes, regular files, etc. They can also be sockets. On Linux, the /proc/<pid>/fd/<fd> are a special kind of symbolic links which allow you to ...
/proc/[pid]/fd/[0, 1, 2]: No such file or device - even though file exists
1,345,896,409,000
I know that with ipcs(1) command, one can monitor System V message queues, shared memory and semaphores, but how do I monitor POSIX message queues, shared memory and semaphores. For POSIX message queues, I can mount a pseudo filesystem, as stated in mq_overview(7). Thank you in advance for any help.
I don't believe there are any commands that allow you to monitor POSIX message queues specifically. As you mentioned, all of the details are exposed via a pseudo filesystem, usually mounted under /dev/mqueue. Once you've done that, you can then use file management commands like ls, rm, cat, etc. to inspect and manage...
ipcs(1) POSIX equivalent to System V
1,345,896,409,000
I have two cooperating programs. One program just writes its output to a file and the other one then reads from the file and spits the data out for the front end to work with. I have been reading about named pipes and domain sockets, but I am having trouble seeing what advantages they offer to just using a temp file. ...
If you need to save the intermediate file after the processing is done, then inter-process communication (such as through a pipe or socket) is not particularly valuable.  Similarly, if you need to run the two programs at vastly different times, you should just do it the way you're doing it now. Back when Unix was cre...
Advantages of using named pipes and sockets rather than temporary files
1,345,896,409,000
I'd like to know how to create a terminal device to simulate a piece of hardware connected through a serial port. Basically, tty device with a certain baud rate that can be read from and written to between two processes. From what I understand, a psuedo-terminal is what I'm looking for, and the makedev can apparently ...
That's probably how pty device files get created, but you don't want to do that whenever you want a pty. Any given machine usually has a complement of pty device files already created. Pseudo TTYs are fairly OS specific and you don't mention what you want to do this on. For a modern linux, I'd take a look at openpty(3...
Creating a terminal device for interprocess communication
1,345,896,409,000
If file descriptors are specific to each process (i.e. two processes may use the same file descriptor id to refer to different open files) then how is it possible to share transfer file descriptors (e.g. for shared mmaps) over sockets etc? Does it rely on the kernel being mapped to the same numerical address range und...
When you share a file descriptor over a socket, the kernel mediates. You need to prepare data using the cmsg(3) macros, send it using sendmsg(2) and receive it using recvmsg(2). The kernel is involved in the latter two operations, and it handles the conversion from a file descriptor to whatever data it needs to transm...
Sharing file descriptors
1,345,896,409,000
When we run this with a POSIX shell, $ cmd0 | cmd1 STDOUT of cmd0 is piped to STDIN of cmd1. Q: On top of this, how can I also pipe STDOUT of cmd1 to STDIN of cmd0? Is it mandatory to use redirect from/into a named pipe (FIFO) ? I don't like named pipes very much because they occupy some filesystem paths and I need ...
On systems with bi-directional pipes (not Linux), you can do: cmd0 <&1 | cmd1 >&0 On Linux, you can do: : | { cmd1 | cmd2; } > /dev/fd/0 That works because on Linux (and Cygwin, but generally not other systems) /dev/fd/x where x is a fd to a pipe (named or not) acts like a named pipe, that is, opening it in read mod...
Shell: mutual piping of STDIN/STDOUT of two commands [duplicate]
1,345,896,409,000
When I look at journalctl, it tells me the PID and the program name(or service name?) of a log entry. Then I wondered, logs are created by other processes, how do systemd-journald know the PID of these processes when processes may only write raw strings to the unix domain socket which systemd-journald is listenning. A...
It receives the pid via the SCM_CREDENTIALS ancillary data on the unix socket with recvmsg(), see unix(7). The credentials don't have to be sent explicitly. Example: $ cc -Wall scm_cred.c -o scm_cred $ ./scm_cred scm_cred: received from 10114: pid=10114 uid=2000 gid=2000 Processes with CAP_SYS_ADMIN data can send wha...
How does journald know the PID of a process that produces log data?
1,345,896,409,000
Why are pseudo-terminals a seperate feature on Unix-like systems? What makes them superior to a pair of pipes or FIFOs for implementing terminal emulators?
Terminals are different from other forms of I/O, and a terminal emulator needs to present itself as a terminal. A terminal (including a pseudoterminal) has certain attributes, such as its line length and supported control sequences. Programs can ask for these, for example, in general ls will determine whether its ou...
Pseudo-terminals vs. a pair of pipes
1,345,896,409,000
Despite reading through tons of DBus tutorials, I still struggle to understand the whole concept. In my opinion this was one of the best explanations so far: http://telepathy.freedesktop.org/doc/book/sect.basics.dbus.html The reason to use the DBus is because I want to exchange data between different programs. In my o...
Not by convention but to facilitate high-level bindings. Native Objects and Object Paths Your programming framework probably defines what an "object" is like; usually with a base class. For example: java.lang.Object, GObject, QObject, python's base Object, or whatever. Let's call this a native object. The low-l...
What's the sense of DBus objects?
1,345,896,409,000
I have 3 different programs that I would like to intercommunicate with each other. I have an engine that needs to communicate with 2 bots and the bots with the engine. The engine is written in C++ and the bots can be written in any language. The engine writes output to stdout and both bots need to read the output. De...
You've got the < fifo0 in the wrong place. You want it to be engine's stdin, not tee's: mkfifo fifo0 fifo1 fifo2 < fifo0 ./engine | tee fifo1 fifo2 & ./bot1 > fifo0 < fifo1 & ./bot2 > fifo0 < fifo2 Note that many utilities start to buffer their output when it doesn't go to a tty device (here a pipe (or possibly a soc...
Many-to-one two-way communication of separate programs
1,345,896,409,000
Is RabbitMQ, for inter process communication, like pipes and named pipes? How does RabbitMQ compare to named pipes? Except distributed systems. (RabbitMQ, for those who haven't encountered it, is an open source, middleware, enterprise message broker that speaks AMQP.)
Is RabbitMQ, for inter process communication, like pipes and named pipes? No. That's not the best way to comprehend RabbitMQ, or indeed message-passing broker-based middlewares in general. If you are looking for a paradigm to hang your metaphorical hat on in order to start understanding RabbitMQ and its ilk, don't...
are named pipes (mkfifo) the predecessor of RabbitMQ? [closed]
1,345,896,409,000
I grepped the ps output for dbus with the following output: 102 742 0.0 0.0 4044 1480 ? Ss Apr16 27:13 dbus-daemon --system --fork --activation=upstart xralf 2551 0.0 0.0 4076 212 ? Ss Apr16 0:14 /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session dwm xralf 2554 0.0 0.0...
You didn't provide much information about your system though. DBus system usually has two buses: a system bus and a session bus. Session bus is started per user (in your case for root and xralf), lines 3 to 6. Line 2 is a dbus service that was requested by your window manager. A system bus is needed for system-wide m...
dbus-launch and dbus-daemon - what's happening
1,345,896,409,000
This is a combination of programming and Linux question but I think it suits better here. I am writing an application that works with ipcs (shared memory segments) and after each running I am checking if any ipcs are left using the bash command ipcs. I noticed a lot more than I created so I thought they are part of th...
By system clock I mean the clock that tells the time down right of the panel "System clock" generally refers to the clock maintained by the kernel; applications such as date and GUI clocks such as the one you refer to make calls to it like this. Why, out of all the processes that the system runs, does the clock ne...
Why does the clock need a shared memory segment?
1,345,896,409,000
What is the best way of checking current status of different types of IPC in Linux (including uids) ? I want to inspect named pipes, half duplex pipes, unix domain sockets, signals. I know for sys V we have ipcs.
lsof(8) is probably your best option. Lesser options include ipcs(1), fuser(1), netstat(8), ps(1), and rummaging through /proc.
Linux - check IPC stats
1,345,896,409,000
From The Linux Programming Interface under "data transfer" under "communication", we have "byte stream", "message" and "pseudoterminal". Does pseudoterminal belong to byte stream instead, just like how pipe belongs? If not, why?
Consider the various modes a pseudoterminal can be in: in raw mode, it would behave much like a byte stream, but in cooked mode, it becomes more message-like.
Does pseudoterminal transfer byte stream or message?
1,345,896,409,000
I wrote a simple bash script that reads out meta information about currently playing songs via playerctl. Right now the script is just unnecessary polling the information. I would like the script to only be invoked when the song changes. The actual player I am using is mostly spotify. Is there any way I can use signal...
playerctl's github page has an example for polling events with python. The API might give you additional infos.
How do I turn my simple script into a non polling version
1,345,896,409,000
As I understand it, the Linux Security Module (LSM) framework has many hooks which are callbacks for security modules to register functions performing additional security checks before security-sensitive operations. Most of the time, these hooks are placed before the access to an internal data structure like file. One...
I should have posted that earlier but I got some elements of answer from Stephen Smalley, SELinux developper and maintainer, in a conversation on the LSM mailing list, in July 2016. There is no longer an archive for this mailing list for that period, due to MARC stopping archiving that mailing list and Gmane going out...
Why are there no LSM hooks in the POSIX IPC APIs?
1,345,896,409,000
There are empty files like this in my /tmp directory: qipc_sharedmemory_soliddiskinfomemac5ffa537fd8798875c98e190df289da7e047c05 qipc_systemsem_soliddiskinfomemac5ffa537fd8798875c98e190df289da7e047c05 qipc_systemsem_soliddiskinfosem92d02dca794587d686de797d715edb3b58944546 What are they?
These appear to be files that Qt creates during the course of Inter-process communication. The file names indicate that shared memory and semaphores were used.
What are the files in /tmp that start with "qipc"?
1,429,325,339,000
When I run ipcs -m I get below info ------ Shared Memory Segments -------- key shmid owner perms bytes nattch status 0x00000 38699014 user 700 8125440 2 dest 0x00072 2064391 root 444 1 0 0x00000 38830088 user 700 299112 2 dest 0x00000 38862857 user 700 181720 ...
ipcs -m -p shows the shmid and the PID of the process that created it (the "cpid"). It also shows a "last operator" or "lpid" - I don't know what that is (the man page doesn't say so I'd having to dig deeper into the docs or source code to find out, and that's crazy talk!). For example, on one of my systems (which hap...
List processes associated with shared memory
1,429,325,339,000
When you have a Linux application that depends on a library (dynamically-linked), how does the application communicate with the library? What inter-process communication method is used?
None. Because a dynamically linked library lives in the same process' memory space - and thus, no second process exists with which you need to do IPC.
What IPC is used between an application and a library in Linux?
1,429,325,339,000
I am trying my hand on Linux Signals. Where I have created a scenario mentioned below: Initially block all SIGINT signals using sigprocmask(). If sender send SIGUSR1 signal then unblock SIGINT for rest of the process life. However first step is successfully implemented but not able to unblock (or change) process ma...
The kernel will restore the signal mask upon returning from a signal handler. This is specified by the standard: When a thread's signal mask is changed in a signal-catching function that is installed by sigaction(), the restoration of the signal mask on return from the signal-catching function overrides...
Why below code is not able to unblock SIGINT signal
1,429,325,339,000
We have a kernel module that was building fine for RedHat family of Linux distribution, until the recent RHEL7.5. When trying to build on RHEL7.5, we've got an error of: ...error: ‘GENL_ID_GENERATE’ undeclared... Did some reading, and it seems like this is an change since kernel 4.11+, but RHEL7.5 is based on kernel ...
Looking at the git commits for netlink it looks like several changes were made to the structure in version 4.11: First, you can omit the .id field completely from your initializer in genl_family as Linux has removed static family IDs. As well, the genl_register_family_with_ops function is not used any more. Instead, a...
netlink: GNEL_ID_GENERATE definition removed from RHEL7.5 kernel library
1,429,325,339,000
I'm learning how to use Message Queue in Linux and I've found a simple example: https://www.geeksforgeeks.org/ipc-using-message-queues/. With the reader and writer in this link, I can read and write messages through the Message Queue on my Ubuntu. Everything is fine. Well, if I'm right, when we write some messages int...
IPC resources aren’t tied to a given process, so they don’t show up in the data displayed by top, ps etc. You can see this in the example you’re referring to: the message queue is created by the writer but deleted by the reader. To monitor IPC resources, you can use lsipc: lsipc will provide an overview, and lsipc -q...
Is RAM usage of IPC a part of the RAM usage of a program
1,429,325,339,000
I have two processes given by their pids: P1 and P2. Is there are a simple way of chcecking whether these processes are communicating via sockets or other inter-process communication mechanism? I need to know this because I have two seemingly unrelated apps that might be communicating under the hood and I want to know...
You can use lsof -p P1 and lsof -p P2 to see the file descriptors open by the two processes. Then you can look at the list of sockets and pipes they each have open, and see if any of them have the same ID. imac:barmar $ sleep 100 | sleep 100 & [1] 51885 imac:barmar $ jobs -l [1]+ 51884 Running sleep 10...
How to verify whether two local processes are communicating via sockets or ipcs?
1,429,325,339,000
My process deadlocks. master looks like this: p=Popen(cmd, stdin=PIPE, stdout=PIPE) for ....: # a few million p.stdin.write(...) p.stdin.close() out = p.stdout.read() p.stdout.close() exitcode = p.wait() child looks something like this: l = list() for line in sys.stdin: l.append(line) sys.stdout.write(str(len...
parent.py from subprocess import Popen, PIPE cmd = ["python", "child.py"] p=Popen(cmd, stdin=PIPE, stdout=PIPE) for i in range(1,100000): p.stdin.write("hello\n") p.stdin.close() out = p.stdout.read() p.stdout.close() print(out) exitcode = p.wait() child.py import sys l = list() for line in sys.stdin: l.append...
Deadlock on read/wait [closed]
1,429,325,339,000
I wish to send a command to process A, from process B, via a FIFO. The command will be a word or a sentence, but wholly contained on a "\n" terminated line - but could, in general, be a multi-line record, terminated by another character. The relevant portion of the code that I tried, looks something like this: Proce...
Yep, that's exactly what happens: $ mkfifo p $ while :; do cat p ; done > /dev/null & $ strace -etrace=open,close bash -c 'echo -n foo > p; echo bar > p' |& grep '"p"' -A1 open("p", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3 close(3) = 0 -- open("p", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3 close(...
bash: Reading a full record from a fifo
1,429,325,339,000
Obviously O_CREAT and O_EXCL are not required when opening an existing semaphore. O_CREAT is required when creating a new semaphore. O_EXCL is only meaningful when OR-ing with O_CREAT, specifying that if a semaphore with the given name already exists, then an error is returned. Linux manual page for sem_open said that...
Consider the following example: #include <fcntl.h> #include <sys/stat.h> #include <semaphore.h> #include <stdio.h> int main(int argc, char* argv[]) { const char* const sem_name = "lock.sem"; if (argc == 1) { sem_t* const sem = sem_open(sem_name, O_CREAT, 0644, 0); if (sem == NULL) { ...
How to open an existing named semaphore?
1,429,325,339,000
When I do a kill -SIGUSR1 $PPID I get kill: (1) - Operation not permitted . How can I overcome this?
My parent process had died for some reason. This caused the issue. I took care of that and the problem got solved.
Sending SIGUSR1 to parent
1,429,325,339,000
I have a systemd-nspawn container in which I am trying to change the kernel parameter for msgmnb. When I try to change the kernel parameter by directly writing to the /proc filesystem or using sysctl inside the systemd-nspawn container, I get an error that the /proc file system is read only. From the arch wiki I see t...
$ cat /proc/6211/status | grep -i Cap CapInh: 0000000000000000 CapPrm: 0000000000000000 CapEff: 0000000000000000 CapBnd: 00000000fdecafff CapAmb: 0000000000000000 CapInh is the set of inheritable capabilities, which is not useful for the current program, but could be passed on to any programs this process would exec(...
How to increase kernel parameter (`msgmnb`) for a systemd-nspawn container
1,429,325,339,000
There is the Supermicro X10DAi motherboard and the manual is here. On page 1-11 you can see that each CPU has it's own RAM. Let's say program A is offering an API through a local socket /var/run/socketapi. This program is started on CPU 1. Then there is program B connecting to this socket and it's started on CPU 2. Wh...
Yes, CPUs map each other's memory through the CPU interconnect. On Intel-compatible architectures, that is a coherent mapping, so software notices mostly in the form of higher latency when accessing memory connected to the other CPU. As system memory has quite a bit of latency on its own, the difference is not that gr...
How does local socket IPC work on a multi CPU system?
1,429,325,339,000
Is there any way to redirect stdout (1) from that "pipe" (I don't know exacly how I suppose interpret this, I will be glad if someone could explain how to treat this, or give me some read on this) to some other output, eg. file or terminal? -bash-4.2$ ls -l /proc/11/fd total 0 lrwx------ 1 us sudo 64 Sep 24 11:26 0 ->...
Not in a clean or portable way. You have to attach with a debugger like gdb, open some the destination file and dup it into fd 1. As with gdb -p <PID> -batch -ex 'call dup2(open("<PATH>", 2), 1)' That pipe:[digits] is an "anonymous" pipe, as created by cmd | cmd shell construct. However on Linux it's not really anony...
How to redirect running process output from pipe to something else?
1,429,325,339,000
I'm trying to write a little chess program - actually more of a chess GUI. The chess GUI should use the stockfish chess engine in the background when the player plays against the computer. I got stockfish installed and can run it in the terminal and communicate with it via STDIN and STDOUT, for example I can type 'isr...
Since you're already working with C, then I'd suggest you manage stockchess in C as well. There is a library function, popen() that will give you a unidirectional pipe to a process -- that doesn't suite your use case. You can, however, set it up yourself. Consider the following example program: #include <errno.h> #i...
Programming - Communicating with chess engine stockfish / FIFOs / Bash redirections
1,429,325,339,000
I want to store the stdout from a process into a buffer and have the buffer emptied once read, FIFO style. I know that I can pipe the stdout, but the pipe/file will keep growing and contain data that I have already read. I just want the fresh data. command > named_pipe & Are there any other inbuilt methods, similar t...
I don't understand how named pipes don't solve your problem. This example uses two shell interfaces, shell_1 and shell_2. I indent I/O from/to shell_2 more than that of shell_1 to try to differentiate what I/O is occurring from which shell. $ mkfifo my_pipe (shell_1) $ echo hi > my_pipe # Blocks waiting for a reader...
What methods exist for capturing stdout into a buffer that is automatically cleared on read?
1,429,325,339,000
I've done some research about this topic but I didn't understand it quite well. From msgsnd man page : The msgsnd() system call appends a copy of the message pointed to by msgp to the message queue whose identifier is specified by msqid. Does this mean that when i use a msgget to create a message queue the ...
According to man2(msgrcv) enqueue/dequeue operations are handled internally by systemV API. so you don't need to re-implement them just use the provided API. For message queue attributes use msgctl with IPC_INFO command.
Handling multiple messages in message queue
1,429,325,339,000
I'm trying to invoke CreateItem method on org.freedesktop.secrets dbus service. busctl --user call org.freedesktop.secrets /org/freedesktop/secrets/collection/login org.freedesktop.Secret.Collection CreateItem "a{sv}(oayays)b" How can I figure out what kind of arguments to pass for a{sv}(oayays)b signature.
a{sv} dictionary with keys being strings and values variants (oayays) struct of object path (o), two bytearrays (ay) and a string (s) b boolean Check the Secrets API Specification for more details about the parameters for CreateItem.
What is a{sv}(oayays)b dbus signature
1,429,325,339,000
From what I seen online you call kill method in c++ in order to see if the process is alive. the issue with that is PID's get rycled and the same PID your looking for may not be the same process. I have a program that has two processes that are not children of each other. The only way to communicate with them is IPC. ...
The solution is to either reserve the PID on windows by cacheing and not closing the process handle. For POSIX Systems we simply get the process's start time from the kernal OS DEPENDANT! and then check if the cached start time equals the current start time. If it doesn't a PID conflict is detected and it returns fals...
check is Process is Alive from PID while handling recycled PID
1,429,325,339,000
So I wanted to know how files are opened by zsh like .xinitrc, .xprofile, .zprofile, and exactly in which order. So I have decided to strace on zsh process with the grep command to see how the open system call is called and eventually I can decide and order how these files are loaded. My command: strace zsh | grep ope...
strace sends its output to stderr by default. Here, you could do: strace -o >(grep --color open >&2) zsh To run zsh while seeing all system calls that have open anywhere in the name or arguments or return value or: strace -e /open zsh (short for strace -e trace=/open zsh) or: To see the system calls that have open i...
How to trace on continuously running process?
1,400,384,865,000
Is it possible to setup a Linux system so that it provides more than 65,535 ports? The intent would be to have more than 65k daemons listening on a given system. Clearly there are ports being used so this is not possible for those reasons, so think of this as a theoretical exercise in trying to understand where TCP ...
Looking at the RFC for TCP: RFC 793 - Transmission Control Protocol, the answer would seem to be no because of the fact that a TCP header is limited to 16-bits for the source/destination port field.      Does IPv6 improve things? No. Even though IPv6 will give us a much larger IP address space, 32-bit vs. 128-bits, it...
Can TCP provide more than 65535 ports?
1,400,384,865,000
I have a computer with: Linux superhost 3.2.0-4-amd64 #1 SMP Debian 3.2.60-1+deb7u3 x86_64 GNU/Linux It runs Apache on port 80 on all interfaces, and it does not show up in netstat -planA inet, however it unexpectedly can be found in netstat -planA inet6: Active Internet connections (servers and established) Proto Re...
By default if you don't specify address to Apache Listen parameter, it handles ipv6 address using IPv4-mapped IPv6 addresses. You can take a look in Apache ipv6 The output of netstat doesn't mean Apache is not listening on IPv4 address. It's a IPv4-mapped IPv6 address.
netstat — why are IPv4 daemons listening to ports listed only in -A inet6?
1,400,384,865,000
I have a system that has two network interfaces with different IP adresses, both of which are in the public address range (albeit via NAT in the case of the first one) and both of which have different gateways. (Long story, it's for testing purposes) The problem is that right now, if I try to ping the address on the s...
You are misunderstanding the problem. Not every packet is a response and not every packet can be matched to some other packet such that "same network interface as they came in on" makes sense. What you want to do is select the gateway for a packet based on its source IP address. This is called source-based routing or ...
Two interfaces, two addresses, two gateways?
1,400,384,865,000
I have a system with two NICs on it. This machine, and a few accompanying devices will be moved and attached to different LANs or sometimes it'll be using dial-up. eth0: - 10.x.x.x address space - no internet gateway - only a few devices eth1 (when used): - 172.16.x.x or 192.168.x.x or other address ...
The DHCP server configuration is wrong. It must not send a default gateway option when it can't provide routing to the rest of the world. If it does send that option then any client may assume that it can send packets for any off-link destination to the specified default gateway. So your box is right in using the defa...
Can I prevent a default route being added when bringing up an interface?
1,400,384,865,000
We can use the syntax ${var##pattern} and ${var%%pattern} to extract the last and first section of an IPv4 address: IP=109.96.77.15 echo IP: $IP echo 'Extract the first section using ${var%%pattern}: ' ${IP%%.*} echo 'Extract the last section using ${var##pattern}: ' ${IP##*.} How we can extract the second or third s...
Assuming the default value of IFS you extract each octet into it's own variable with: read A B C D <<<"${IP//./ }" Or into an array with: A=(${IP//./ })
Bash: Extract one of the four sections of an IPv4 address
1,400,384,865,000
I try to configure static IPv4 & IPv6 configuration on CentOS 6.2. The configuration below works perfectly : # ifconfig eth0 x.x.x.x/29 # route add defalt gw x.x.x.y # ip addr add dev eth0 XXXX:C810:3001:D00::3/56 # ip -6 route add default XXXX:C810:3001:D00::1 However, I want to keep this configuration after a rebo...
Network Manager is trying to override your static configuration settings. As root or sudo user, run: service NetworkManager stop If you don't have service, try: /etc/init.d/NetworkManager stop Also, you can set the static interfaces to not be managed by the NetworkManager, which is what I did in my CentOS configs me...
Static IPv4 & IPv6 configuration on CentOS 6.2
1,400,384,865,000
I have to set up a FTP server on my machine. I have installed vsftpd using the command: sudo apt-get install vsftpd I then edited the configuration file vsftpd.conf in the location /etc. The file contains: #Set the server to run in standalone mode listen=YES #Enable anonymous access local_enable=NO anonymous_enable=...
Remember to comment out listen=YES in your vsftpd.conf file so that you don't run your vsftpd in standalone mode It fixed the problem in my case.
Installing vsftpd - 500 OOPS: could not bind listening IPv4 socket?
1,400,384,865,000
On a server wget-1.16 takes 8 minutes to complete: $ wget http://http.debian.net/debian/dists/stable/Release -O - --2017-06-12 23:44:40-- http://http.debian.net/debian/dists/stable/Release [4693/5569] Resolving http.debian.net (http.debian.net)... 2001:4f8:1:c::15, 2605:bc80:3010:b00:0:deb:166:202, 2001:610:1...
curl and wget do not use different mechanisms for resolving domains (they're using getaddrinfo()). However, curl implements a fast fallback algorithm to improve the user experience in cases where IPv6 connectivity is less than good. This algorithm is described in detail in RFC 6555 (Happy Eyeballs): https://www.rfc-ed...
wget uses ipv6 address and takes too long to complete
1,400,384,865,000
When I run ip to get the ip address, I'm getting $ ip link 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: wlp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group defaul...
Apparently ip broke up the MAC address (now in the ip link (device) interface), and the network ip address. The command ip address is what shows the network addresses, 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 ...
How can I get the ipv4 address from `ip link` like I used to see with ifconfig?
1,400,384,865,000
I'm currently stumped by a strange problem… I have a dual stack host to which I want to SSH. If I connect via IPv6 everything works like expected datenwolf@foo ~/ > ssh -6 bar.example.com Password: datenwolf@bar ~/ > However when doing the same via IPv4 it fails datenwolf@foo ~/ > ssh -4 bar.example.com Password: Pe...
After things getting stranger and stranger (see the thread of comments in my question) I finally figured it out. First things first: The authentication process did fail in pam_access.so however not due to some misconfiguration in /etc/security/access.conf as it was suggested. To understand why, we must look at the set...
SSH login via IPv6 successfull while using IPv4 to the same host yields "Permission denied"
1,400,384,865,000
I have two machines connected in link local IPv4 over a CAT6 cable. Is there a way from host1 that I can determine host2's IPv4 address? I'm on an Debian-derivative running kernel 3.2.0-34-generic.
Yes, already posted in the comments as a verified solution, but posting as an answer anyway. Try using mDNS. One should install avahi-daemon on the machine you want to resolve (e.g. host2), and at least some Avahi client libraries appropriate for your client system (e.g. host1). These client libraries are usually inst...
Detect other machine's address in link local?
1,400,384,865,000
When it comes to packet filtering/management I never actually know what is going on inside the kernel. There are so many different tools that act on the packets, either from userspace (modifying kernel-space subsystems) or directly on kernel-space. Is there any place where each tool documents the interaction with othe...
Most folks I know who are working with the Linux network stack use the below diagram (which you can find on Wikipedia under CC BY-SA 3.0 license). As you can see, in addition to the netfilter hooks, it also documents XFRM processing points and some eBPF hook points. tc eBPF programs would be executed as part of the i...
How do packets flow through the kernel
1,400,384,865,000
Suppose I want to use : $ ip ntable show dev eth0 inet arp_cache dev eth0 refcnt 4 reachable 20744 base_reachable 30000 retrans 1000 gc_stale 60000 delay_probe 5000 queue 31 app_probes 0 ucast_probes 3 mcast_probes 3 anycast_delay 1000 proxy_delay 800 proxy_queue 64 locktime 1000 inet6 ndis...
In IPv4 networks the neighbour tables are written with usage of the Address Resolution Protocol. Those tables are commonly known as "ARP-tables". They resolve IP-addresses (addresses in the network layer) in MAC-addresses (addresses in the link-layer) and vice-vesa. You can list the entries of this table by the comman...
What's ndisc_cache?
1,400,384,865,000
I am looking at the output of lsof -i and I am getting confused! For example, the following connection between my java process and the database shows as IPv6: [me ~] % lsof -P -n -i :2315 -a -p xxxx COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME java xxxx me 93u IPv6 2499087197 0t0 TCP 192....
In Linux, IPv6 sockets may be both IPv4 and IPv6 at the same time. An IPv6 socket may also accept packets from an IPv4-mapped IPv6 address. This feature is controlled by the IPV6_V6ONLY socket option, whose default is controlled by the net.ipv6.bindv6only sysctl (/proc/sys/net/ipv6/bindv6only). Its default is 0 (i.e. ...
Why does lsof indicate my IPv4 socket is IPv6?
1,400,384,865,000
I'm going to explain my question with an example. I have two servers, A and B, both runs Debian 7.8, both have dual-stack connection to the Internet (I don't know if it matters but they even have the same amount of IPv6 addresses) and they both have the same version of whois installed (without any config file). Now, w...
Turns out that it's about configuration of getaddrinfo, which is controlled at /etc/gai.conf. More information about how it can be solved: https://askubuntu.com/questions/32298/prefer-a-ipv4-dns-lookups-before-aaaaipv6-lookups
How does Debian select or prioritize IPv4 and IPv6 connections?
1,400,384,865,000
If I am listening on :::80, is it listening on all ipv6 or all ipv6+ipv4? This is my netstat -tln: tcp 0 0 :::8080 :::*
A listening socket that is bound to ::, i.e. any address IPv6 address (INADDR6_ANY), may or may not also listen to connections using IPv4. This depends from several things: Some operating systems are what is known as dual stack, and on those operating systems this depends from whether the IPV6_V6ONLY socket option is...
does :::80 in netstat output means only ipv6 or ipv6+ipv4?
1,400,384,865,000
I'm working on a custom Ubuntu 20.04 server and am trying to get a dhcp IP for it. The server has so far run on a static IP and when I run dhcp or dhclient it says dhcpd: command not found and dhclient: command not found. The /sbin has no dhcpd or dhclient directories but there is a /etc/dhcp folder which contains dhc...
If you receive command not found when trying to run dhcp or dhclient, it's possible that these are not installed. To install the DHCP client utilities run: sudo apt install isc-dhcp-client This will install the isc-dhcp-client package, which includes the dhclient. After the installation, you should be able to use the ...
dhcpd or dhclient not found
1,400,384,865,000
I have an embedded system built using buildroot. I have had a number of network issues, one of which is that my machine cannot see its gateway despite it being on the same subnet. I have tried using wireshark to analyse what is going on without success so as a last resort, I am considering trying to turn off support f...
I agree with Ulrich, that this doesn't sound like an IPv6 problem. However, here's how to disable IPv6. In /etc/sysctl.conf set the following options: net.ipv6.conf.all.autoconf = 0 net.ipv6.conf.all.accept_ra = 0 net.ipv6.conf.all.disable_ipv6 = 1 If you don't have /etc/sysctl.conf just create it and add those lines...
How can I disable IPv6 in custom built embedded setup
1,400,384,865,000
The task includes an option with an undefined variable. The error was: ansible_all_ipv4_addresses is undefined. Why would I be getting this error, if I am connecting over ipv4? I'm trying to dump this like, "{{ ansible_all_ipv4_addresses[0] }}" And I can verify that it is valid, $ ansible -u centos -m setup 10.1.3...
For me the problem was that my playbook had gather_facts: false Set at the top of my playbook. As to why the use of facts does not work with the debug module, for that see this question How can the debug module get access to facts on the command line?
Ansible fact is undefined: `ansible_all_ipv4_addresses` is undefined
1,400,384,865,000
OS: GNU/Linux Debian 9.2 64-bit I disabled IPv6 on one of my servers. And now I'm getting this in mail: exim paniclog ... IPv6 socket creation failed: Address family not supported by protocol How do I get rid of it?
First of, man needs to disable IPv6 in exim4. In the following file: /etc/exim4/update-exim4.conf.conf Make sure this line is there, if not, add it, or change it: disable_ipv6='true' But I tried only this solution and the mail is still coming, so digging further... In the same file, make sure this line is set to tru...
IPv6 socket creation failed: Address family not supported by protocol
1,400,384,865,000
Similar questions have been asked before but my setup is a little different and the solutions to those questions are not working. A have a CentOS 6 server running iptables with 5 interfaces: eth0: Management 136.2.188.0/24 eth1: Cluster1 internal 10.1.0.0/16 eth2: Cluster1 external 136.2.217.96/27 eth3: Cluster2 int...
OK, I figured it out. What I had to do was add the internal subnet route to each route table then set rules to control what interface traffic routes to/from. Then in iptables marking packets with the mangle table was not needed, just the typical forward and nat rules. ip route add 136.2.178.32/28 dev eth4 table 1 ip...
NAT box with multiple internal and external interfaces
1,400,384,865,000
It seems that when resolving hosts on Alpine Linux, the default behavior is to try IPv6 first and falling back to IPv4. But sometimes it takes a lot of time to resolve, and there are connections when IPv6 is blocked entirely making it frustating. Is there a way to configure the resolver to try IPv4 first?
I've just found that I can disable IPv6 entirely and that makes the trick for me. Adding to /etc/sysctl.d/local.conf (source): # Force IPv6 off net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1 net.ipv6.conf.eth0.disable_ipv6 = 1 And reloading the configuratio...
How to resolve IPv4 first on Alpine Linux?
1,400,384,865,000
I'm trying to work out how to connect an inbound IPv4 connection to a port listening on a IPv6 port on a CentOS box. To demonstrate on a vanilla CentOS 7 server: Confirm bindV6only is disabled $ cat /proc/sys/net/ipv6/bindv6only 0 Run netcat listening on a IPv6 port nc -lvn6p 80 On another shell, atte...
I don't know if this is your problem, but running yum install nc on centos 7 will install nmap-ncat, which does set the SOL_IPV6/IPV6_V6ONLY socket option itself on ipv6 sockets: # strace -e trace=setsockopt nc -lvn6p 80 Ncat: Version 7.50 ( https://nmap.org/ncat ) setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 s...
How to connect to a IPv6 service using IPv4 connection on CentOS 7?