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.

Filter by
Sorted by
Tagged with
-2
votes
1answer
54 views

Exec format error

I know this gets thrown around a lot, but it just didn't make sense to me. So, I compiled C code using the installed gcc compiler but it just would execute. Many other posts said that it was probably ...
9
votes
4answers
5k views

When to call fork() and exec() by themselves?

I'm learning about fork() and exec() commands. It seems like fork() and exec() are usually called together. (fork() creates a new child process, and exec() replaces the current process image with a ...
1
vote
1answer
35 views

script hangs due to `exec` on AiX servers with ksh shell

Below script runs fine on all Servers in my infrastructure. However, I recently discovered that it fails to complete execution and simply hangs on Aix servers with ksh shell. cat myscript.sh export ...
0
votes
1answer
39 views

Trouble with the command “-exec ls -l {} ”

I was working on a lab and was having trouble with the function of part of a command we are supposed to learn. Here it is: find . -name "*.txt" -exec ls -l {} \; I have determined that the ...
0
votes
1answer
44 views

How did Linux load this exe compiled with C#? [duplicate]

I just discovered something really surprising. I can compile a simple C# hello world on my windows computer using csc (from Visual Studio), copy the resulting exe file to my Linux computer, and ...
0
votes
3answers
3k views

How to sudo + exec?

I need to use sudo to run process as a different user. But how to use sudo with exec like: sudo -u www-data exec php -r 'sleep(2); echo 5;' to replace the sudo process? Why and requirements? ...
1
vote
0answers
44 views

Prompt is not shown after running a script with an “exec” command redirecting stdout and stderr [duplicate]

An example script is shown below. The meaning of the syntax - exec > >(tee -a "$file" "$sec_file") 2>&1 , is to print to the console the stdout and sdterr , and also ...
1
vote
2answers
36 views

perl cannot `exec` to binary

In my fresh installation of Debin, perl intepreter is installed by default (in other words, I have no other perl packages yet). However, trying this: $ls a.cpp b.cpp $ perl -e 'system "g++ -o a....
2
votes
1answer
75 views

Identical execve causes “Permission denied” for one program but not another

Permission denied shows up when I try to open some attachment in Thunderbird. Yet, it doesn't look as a Thunderbird bug, because when I strace the process I see it issues the correct call. Yet it ...
0
votes
2answers
96 views

Output tee to stdout while writing to a FD using here-strings

I am trying to output tee while writing to a custom file descriptor. Example: exec 4>"/tmp/testfile.txt"; # open FD 4 tee -a >&4 <<< "Output this to stdout" # ...
0
votes
1answer
792 views

How to use parameter expansion with find -exec {}? [duplicate]

I want to incorporate something like: for f in */*; do mv "$f" "${f%/*}/foo.${f##*.}"; done Into my find x -exec y {} \;-style workflow. The for loop construct & "$f" variable will ...
0
votes
0answers
14 views

Safety of here document redirecting to file descriptors?

I want to run multiline python scripts by pasting into bash terminal. I discovered here documents and file redirection, as quoted from this answer; exec 3<<'HERE' import sys print("Line Zero!")...
0
votes
1answer
1k views

Cgroup memory limits and process killing

I have the following situation: (The following functions are ones taken from python) I have a process A which is running and has a cgroup memory limit set on it. I fork a child process from A using ...
3
votes
3answers
67 views

Move files that have a value above a threshold in any row of a specific column

I have a large number of files in a particular folder. I would like to move these files to a subfolder ONLY IF they have at least 1 value above 0.5 in any row of column 4. In a separate command I'd ...
17
votes
6answers
6k views

Choose interpreter after script start e.g. if/else inside hashbang

Is there any way to dynamically choose the interpreter that's executing a script? I have a script that I'm running on two different systems, and the interpreter I want to use is located in different ...
0
votes
0answers
32 views

Mount does not work in script when run by php

So I have a script that's placed in my apache2 html folder and should be executed by an http post. The script requires root (I know that's not safe at all, ignore that please), so I set the user www-...
0
votes
1answer
78 views

exec command won't accept xargs, hangs on command input

I'm not super familiar with exec. I was running through some tests and examples. I wanted to pass a command written in a file to it. I'm expecting that command to be run with exec just as if it were ...
0
votes
1answer
60 views

Why does find and exec mv not move all files?

The current working directory has multiple test files numbered between 1 to 100. These are titled 1.txt through to 100.txt. The command find . -maxdepth 1 -regextype posix-egrep -regex '.*/[ -._&...
3
votes
1answer
298 views

What is this script doing?

#!/bin/bash echo 123456789 > out.txt exec 3<> out.txt read -n 4 <&3 echo -n 5 >&3 exec 3>&- Was asked the content of out.txt at the end of script, in an interview ...
0
votes
1answer
53 views

Where is do_execve located?

In Linux, there is a function called do_execve in fs/exec.c. Where is the object file of the function located after Linux has been compiled? Where is the .ko file that contains it?
1
vote
1answer
34 views

How to find a file and copy its directory?

I use the following command to find a file and copy it somewhere else, find /search/ -name file.txt -exec cp -Rp {} /destination \; How can I copy all files and subdirectories in the parent ...
21
votes
2answers
2k views

Is there a POSIX way of setting zeroth argument of a target application?

In bash you can use exec -a and in zsh you can alternatively also set ARGV0 to execute a program with a certain zeroth argument but is there also a POSIX way of doing so? As suggested in this one ...
0
votes
0answers
77 views

Adding a prefix to output from find and exec

I need to run a command on multiple files. The output should be cor_FILENAME and cov_FILENAME and hence I have the following: find . -name "*.tsv" -exec fastspar --otu_table {} --correlation ...
1
vote
1answer
25 views

Persist file redirection between exec calls

Is there a way to persist file redirection commands between exec calls? For example, there are two bash scripts. In script 1, I am setting up redirection of stdout and stderr to file. Then exec-ing ...
31
votes
2answers
7k views

reason for exec in wrapper scripts

I have seen wrapper script examples which in a nutshell are following: #!/bin/bash myprog=sleep echo "This is the wrapper script, it will exec "$myprog"" exec "$myprog" "$@" As seen above, they ...
3
votes
1answer
51 views

Does find -exec find all results up front, or will it find results added while executing on the previous results?

So if I am downloading say 5000 audio files, each 5 seconds long, and after the first 1000 download, I run: find . -iname "*.wav" -exec play {} \; Will that play only the 1000 files that were ...
32
votes
2answers
72k views

Using exec and tee to redirect logs to stdout and a log file in the same time [duplicate]

In a bash script, how can I redirect all standard outputs to a log file and tee the output on the screen using exec ? log_file="$HOME/logs/install.txt-`date +'%Y-%m-%d_%H-%M-%S'`" [ -f "$log_file" ] |...
-1
votes
3answers
105 views

How can I use two bash commands in -exec of find command? WITH GREP

I would like to do the same as How can I use two bash commands in -exec of find command? but with grep as the second command. The solutions posted for that prior solution don't work when grep is the ...
0
votes
1answer
44 views

fork(), exec() sequence with object file formats?

It's my understanding that POSIX systems rely on certain linker formats to organize memory during a fork() exec() sequence of calls. a.out, COFF and ELF are widely known formats of binary object ...
2
votes
2answers
190 views

Coping with filenames starting with a dash (“-”) when using `-exec` and `xargs`

I am following this question though some of the file names here contain a dash at the beginning of the filename. This is interpreted as an additional option for cp. Following another question (on ...
0
votes
0answers
42 views

Linux: why to execute a program first we need to copy current one? [duplicate]

Seems to me it is so general question I wanted to ask on Computer Science site but could not find proper tags, so asking here. Mods please move if appropriate. As I've read in many places, e.g. here ...
2
votes
3answers
1k views

Specifying redirection options through a variable, in an exec command

I want to be able to specify the redirection command/options via a variable (that I might set based on certain conditions, etc.). But when I run this bash script for example : REDIRECT=">>test" ...
0
votes
3answers
57 views

Find and copy files where the destination directory is based on a part of the file name

I'm looking to do a linux sh script that parse a folder to look for a certain extension copy all these files in a certain folder based of a part of the file name. Currently I succeeded to create two ...
0
votes
2answers
1k views

Order a list of zipfiles, by date modified, then unzip them in that order

I have a list of zip files, that must be extracted by date modified, they contain updated images and the strange way the local mls provides them means that newer zip files container newer versions of ...
24
votes
2answers
3k views

Does POSIX guarantee the paths to any standard utilities?

From C, what's the easiest way to run a standard utility (e.g., ps) and no other? Does POSIX guarantee that, for example, a standard ps is in /bin/ps or should I reset the PATH environment variable ...
11
votes
1answer
5k views

What does & do in the middle of “exec &>/dev/null”?

My command is: exec &>/dev/null What does this & and full command do here? I know it is being redirected to the bit-bucket.
1
vote
2answers
332 views

Why does `find -type d -exec rmdir {} \;` command produce “No such file or directory message”

For testing purposes, I created the following directories. user@linux:~$ mkdir dir0{1..3} user@linux:~$ ls -l total 12K drwxr-xr-x 2 user user 4.0K Mei 31 10:45 dir01 drwxr-xr-x 2 user user 4.0K ...
2
votes
1answer
139 views

Do the strings accessible via global variable `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 ...
3
votes
1answer
14k views

/bin/sh: 0: Can't open sh

I'm trying to run a simple C program. #include <stdio.h> #include <unistd.h> extern char** environ; int main(){ // execl("/bin/sh","sh","-c","/bin/ls -l",(char *) NULL); char* argv[...
0
votes
2answers
130 views

Chaining find exec and a while loop

I'm trying to stack a find command so that the results it returns only contains files with "warning:" or "error:" text within them. I also require those results in a specific format so I'm using exec ...
0
votes
2answers
79 views

Print all subdirectories in the current directory that do not contain a .git

I'm trying to write a bash line that will look at all the subdirectories in my current folder and tell me if any do NOT contain a ".git". Pseudo: for subdir in currentdir if .git does not exist ...
3
votes
0answers
184 views

How does linux decide the load address and entry point when execve an ELF?

When linux execve() an ELF, it will mmap that ELF into the process's memory space and start to run code from the entry point. But how does the kernel decide the load address and entry point of the ELF?...
0
votes
1answer
16 views

CronJob command to delete multiple subdirectories by name in a given directory

I have two IP cameras which are sending image snapshots to an FTP server every 10 seconds, from 08:00 to 20:59. The directory structure looks like this: `-- public_html `-- securitycams |-...
2
votes
1answer
353 views

How to execute something in current shell [duplicate]

I want to create a bash script or something similar that I can execute in the current shell: echo '#!/bin/bash export foo="bar" ' > zoom.sh but if I want to run this script in the current ...
0
votes
1answer
291 views

Redirecting to both screen and file

I'd like to redirect all of the output of the commands I ran to a file, in addition to having them printed on the screen. I want this to happen automatically, I don't want to pipe into tee everytime ...
23
votes
3answers
96k views

How to “correctly” start an application from a shell

I find it hard to phrase the question precisely but I will give my best. I use dwm as my default window manager and dmenu as my application launcher. I hardly use GUI applications aside from my ...
-2
votes
1answer
215 views

Does execvp() account for logical operators?

In my class assignment I'm supposed to make my own command shell. In the shell, I am supposed to have it take various command line arguments including logical operators such as && and ||. I ...
2
votes
2answers
261 views

Does running exec do anything?

Does running exec in an interactive shell do anything? I mean simply exec, with no parameters whatsoever. What about in a script? If it does do something, what does it do?
1
vote
2answers
937 views

exec command in bash loop for webscrapping

Here is a simple script which is curling https://unix.stackexchange.com/ and storing the result into an array, which is working fine. #!/usr/local/bin/bash [ -f pgtoscrap ] && { rm pgtoscrap; ...
3
votes
1answer
76 views

Exit status of command in pipeline

I have come across this code but cannot understand exec >&p edit 1 to my understanding : #! /usr/bin/ksh exec 4>&1 ## standard output is first saved as file descriptor 4 ...

1
2 3 4 5