Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [exec]

The exec() family of functions replaces the current process image with a new process image, retaining the pid and pipes of the old process. This tag is also used for the shell built-in which can be used to replace the current shell with a program or various redirection-related stuff.

-1
votes
1answer
15 views

bash - use exec for file descriptors using environment variables

LOCK_FD=200 LOCK_FILE=/tmp/lock-file exec ${LOCK_FD}>${LOCK_FILE} I get an error exec: 200 not found This however works LOCK_FD=200 LOCK_FILE=/tmp/lock-file eval "exec ${LOCK_FD}>${LOCK_FILE}...
2
votes
1answer
31 views

using both trap and exec to redirect output to tee in bash

I have script that reads lines from a file, processes each line. I'd like to be able to do some "post-processing" in a way that even when the script didn't finish reading all lines because I pressed ...
1
vote
1answer
30 views

What happens to the old stack, heap, and (initialized and uninitialized) data segments after execve() call?

Manpage of execve() says execve() executes the program pointed to by filename. This causes the program that is currently being run by the calling process to be replaced with a ...
10
votes
2answers
1k views

Why is vfork() intended to be used when the child process calls exec() or exit() immediately after creation?

Operating System Concepts and APUE say With vfork(), the parent process is suspended, and the child process uses the address space of the parent. Because vfork() does not use copy-on-write, if ...
0
votes
1answer
50 views

How can I add find exec command into bashrc?

find . -name "*.mov" -exec bash -c 'ffmpeg -i "{}" -c:v libx264 -crf 20 -pix_fmt yuv420p "${0/.mov}.mp4"' {} \; Above command works perfectly when I run it manually but I could not put it within a ...
1
vote
1answer
18 views

Linux find exec - output to a different directory

I'm trying to come up with a short script to edit some csv files. First, I need to replace delimiters, then change encoding to UTF-16. I would like to do this in two steps, saving the results in two ...
0
votes
0answers
29 views

Logging output of scripts called inside another script

Inside bashscript, I am using exec and tee to redirect logs to stdout and a log file in the same time - Unix & Linux Stack Exchange. exec &> >(tee -a "${LogFile}") I am sourcing ...
0
votes
0answers
27 views

Running Commandline Scripts Through PHP

I am having difficulties running bash scripts with php's exec() and wanted to get some suggestions. I would love to be more flexible in this area because I can see a lot of potential for my small ...
0
votes
0answers
32 views

Executing a script after a TCP connection closes

As the title mentions, I'm trying to figure out a way to execute a given script (a file) after a TCP connection closes, and if possible filter out the interface it was going through. Now, what i want ...
2
votes
1answer
45 views

execl() is not executing a command without its absolute path

I have C program saved under /usr/sbin/. This program prints "Hello World" every two seconds. I can call/execute this program from any folder. When I write C program with system("a.out"); in it, it'...
1
vote
1answer
33 views

What properties of an unprivileged process are preserved during an `execve` call?

I am teaching an Operating Systems course and trying to wrap my mind around the fork/execve technique for creating new processes. My current understanding is that a fork make a complete copy of the ...
1
vote
1answer
31 views

find - exec to remove directories with a dollar [duplicate]

In maven local repository directories with dollar name - unresolved properties? I have outlined how I ended up with a few dozen directories that have a dollar sign in their filename. I tried to get ...
1
vote
1answer
134 views

fork() and COW behavior after exec()

We understand the COW behavior after a fork (as for example described here) as follows: fork creates a copy of the parent's page table for the child and marks the physical pages read only, so if any ...
2
votes
3answers
281 views

find . * -exec ll {} \; -> with just one result instead of four

I'd like to use find command to search all files in one directory: find . * -exec ll {} \; Result shows four (!) results per file: file123 ./test/file123 file123 test/file123 Is it possible to ...
0
votes
3answers
61 views

What does `exec “$@”` do?

I've been seeing this in a lot of docker-entrypoint.sh scripts recently, and can't find an explanation online. My first thoughts are that it is something to do with signaling but that's a pretty wild ...
1
vote
1answer
177 views

How can I make a specific process exec a given executable with ptrace()?

I am trying to force the init process of an embedded Linux system to exec() my own init program (systemd) so that I can test an external filesystem before writing it to the system's flash (and risk ...
0
votes
1answer
32 views

Why would `read -s` behaves differently than `read` if killed with `ctrl-c`?

Consider this script: #!/bin/bash echo "hi there $(whoami)" [ "`whoami`" = "root" ] || { exec sudo -u root "$0" "$@" echo "this is never called" } read -s -p "enter stuff: " stuff echo "answer:...
0
votes
2answers
92 views

Should exec always be the last line of shell script?

I have a shell script that does the following: export FOO=foo # step 1 /usr/bin/java my-server # step 2 This shell script is launched by a parent program that needs to know the PID of the ...
0
votes
0answers
72 views

AIX kernel internal stats of nmon: fork vs exec

Why the values of fork and exec stats shown on the kernel internal stats of nmon utility in AIX systems (k option) are so different? Usually the shown fork value is greater than the exec value, ...
-1
votes
2answers
77 views

Unable to set LS_COLORS in bash using script

I am trying to set the LS_COLORS environment variable using a launcher script. However this variable is not being set. Steps Downloaded LS_COLORS to ~/.dircolors Added TERM=xterm-newTerminalEmulator ...
0
votes
0answers
221 views

find with -exec option is not working

I'm trying to use find command (Solaris 11) with -exec option but it seems something is wrong. The command is find / \( -fstype nfs -o -fstype cachefs -o -fstype ctfs -o \ -...
1
vote
1answer
178 views

replacing current shell with execl()

In the following C program: #include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(void){ char *shell = getenv("SHELL"); execl(shell, NULL, NULL); ...
0
votes
2answers
136 views

Dropping filename extensions with find -exec

When using find, how can I drop the original filename extension (i.e. .pdf) from the second pair of -exec braces ({})? For example: find ~/Documents -regex 'LOGIC.*\.pdf' -exec pdf2svg {} {}.svg \; ...
0
votes
1answer
27 views

Passing variables through exe

#!/bin/bash # useradd1.sh - A simple shell script to display the form dialog on screen # set field names i.e. shell variables Name="" OPAC="" Intranet="" mysqlroot="" password="" # open fd # exec 3>...
1
vote
1answer
37 views

Does `exec < somefile` behave the same as `source somefile`

$ cat somefile sleep 100 $ exec < somefile $ sleep 100 Does exec < somefile behave the same as source somefile except that its invoking process terminates upon its completion? Thanks.
6
votes
1answer
419 views

Why does ` exec 2>somefile` hang? [duplicate]

Why does exec >somefile return immediately, while exec 2>somefile doesn't and hang on indefinitely? Thanks.
0
votes
2answers
62 views

will the sleep command in this command ever be executed?

Motivated by How can I change my command to run without superuser privilleges but with the changed limit value?, in a bash shell, if I run exec su $LOGNAME && sleep 100 will the sleep ...
1
vote
1answer
62 views

Does bash calls `execve()` without making further change to how `execve()` treats the signal dispositions?

Bash manual says When a simple command other than a builtin or shell function is to be executed, ... traps caught by the shell are reset to the values inherited from the shell’s parent, and ...
0
votes
1answer
48 views

Change stdout/stderr output device

By default if we run foo(){ echo "myfoo" } it will go to stdout. My question is, for a bash script or function, is there a programmatic way to change the device so that commands don't ...
0
votes
3answers
111 views

Read from file descriptor and write to stdout

I want to prepend something to each line of output in a script, for every command. I was thinking of doing something like this: rm foo mkfifo foo exec 3<>foo cat <&3 | while read line;...
0
votes
0answers
83 views

script appears to run with no progress

This script is to find a list of files stored in a text file, and if the files are found, copy them to a specific location. So far I have had success running the portions up to but not including the ...
0
votes
0answers
82 views

how to know if script execute from local machine or by external engine

we have the following script name checkDataonDataNode_server.bash this script can run local on the linux machine as ./checkDataonDataNode_server.bash or from some win machine that execute this ...
1
vote
2answers
91 views

find + how to verify that all files and folders are with groups and owner hdfs:hadoop

we want to check that all files and folders under /hadoop/hdfs are with permissions - hdfs:hadoop is it possible to do this test with find command ? in case find capture files/folder that not have ...
0
votes
1answer
43 views

Do the strings accessible via global vairable `environ` not reflect any change to the environment?

From https://unix.stackexchange.com/a/436631/674 the file /proc/$$/environ ... does not reflect any changes to the environment, but just reports what the program received when it was execed by the ...
0
votes
0answers
86 views

strace output has dash/hyphen prefix

What does the - prefix signify within ["-bash"] within the line below from the output of an strace command on sshd to trace execve calls? All other execve calls were unprefixed; only bash shows the ...
0
votes
1answer
44 views

Shell script – New script not inheriting values from parent script after `exec`

I wrote a shell script named testmain.sh: username="ravi" echo "The main ProcessId: " echo $$ exec ./process.sh With process.sh being: echo "In subprocess the process ID is:" echo $$ echo $username ...
0
votes
1answer
42 views

How to search for a file by name pattern and execute a command in its directory?

What the following command should do, is to search for all invoice pdf files and check if there is a thumbnail file inside the same directory. If not, it should print the directory. Later I will add a ...
3
votes
2answers
366 views

What does the interpreter reported by `file` refer to?

I'm trying to run perl executable provided by a debug library on Ubuntu 16.04, but for some reason the file "isn't executable" even though it seems to be a match for my architecture. The perl ...
0
votes
2answers
48 views

“find” with multiple conditions to copy on other hard drive using babun

I m trying to copy massive pictures on a messy old hard drive that I can t open on Windows file Explorer (don t ask...) and I have to for the seek of helping my dear Grandma. I can do, navigate in it ...
1
vote
2answers
88 views

Why pass the argument to vi as vi itself? [closed]

Whats the reason behind passing the first argument to vi as vi itself like the following: /bin/vi vi Why not just write : /bin/vi The only difference that I have seen between the two commands is ...
0
votes
1answer
269 views

Piping Find and Move Command Output to a file

I'm executing the following command and the output is not going to the move.log file. Am I missing something in the command? find /db_backups/30_plus_days -type f -mtime +90 -exec mv {} /db_backups/...
0
votes
0answers
27 views

How to redirect stderr and stdout to log, but only stdout to console [duplicate]

I want to send both stderr and stdout to a log file, but keep the console output nice and clean with just stdout. I am using set -x. I understand I need to use a combination of exec and tee but I ...
1
vote
2answers
1k views

Bash Script exec file descriptor returning “not found”

I want to set all debugging output to a log file. So I checked command line - bash: set -x logs to file | Ask Ubuntu and followed the instructions. test-script: #!/bin/bash exec 5 >/var/log/test....
1
vote
0answers
111 views

Modifying .desktop file to scale application display

I'm using the KDE desktop with Fedora 27 on two different machines. I found a handy trick for scaling Spotify by modifying the .desktop file in /usr/share/applications as such: Exec=spotify --force-...
6
votes
2answers
679 views

What logic does the command “exec tail -n +3 $0” from grub2 config have?

Creating custom menu entry, got stuck on this command: exec tail -n +3 $0 Tried it in terminal, got weird result, cannot understand, what this command exactly does and why grub needs it. Could you ...
0
votes
1answer
41 views

how to enable both script to write log to the same path

We have the two scripts father.bash and son.bash, where father.bash runs son.bash as /tmp/son.bash In father.bash we set exec > $log 2>&1 and also in son.bash we set exec > $log 2&...
0
votes
3answers
118 views

how to send standard output and standard error to two files

I use the following syntax in order to send standard output and standard error to $log file log=/var/tmp/install.log info=/tmp/info.log exec > $log 2>&1 how to redirect both standard ...
1
vote
3answers
55 views

Determining if neighbouring process in pipeline has execve'd

I have a sequence of processes in a pipeline: cat haystack | grep needle | my_process | less My understanding is that the shell forks and runs execve for each command concurrently. In my_process, ...
-1
votes
1answer
55 views

Help understanding exec

I need some help to understand the following script sequence. $command .= "n\n\n\n\nt\n7\nc\nw\n"; exec("echo -e \"{$command}\" | /sbin/fdisk {$kernelDevice}"); I can't ...
0
votes
1answer
53 views

exec in php does not work

I'm running apache with php 7.0 on a raspberry pi 3. When I use the curl command on the command line, it works great. But when I use this command in my PHP code, it does nothing. Any idea what this ...