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
1
vote
1answer
33 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
38 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
42 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 ...
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
72 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
93 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
0answers
13 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!")...
3
votes
3answers
65 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 ...
0
votes
0answers
29 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
71 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
57 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
296 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
49 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 ...
0
votes
0answers
74 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 ...
0
votes
1answer
924 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
1answer
50 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 ...
-1
votes
3answers
99 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
43 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
179 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
40 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 ...
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 ...
23
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 ...
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
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? ...
0
votes
2answers
126 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
76 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
171 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 |-...
1
vote
2answers
317 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
341 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
258 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 ...
-2
votes
1answer
207 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
260 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
902 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
74 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
vote
0answers
223 views

awk print tab delimited columns with find execdir

I am trying to print out columns that are separated by tabs. First, I use find command to identify a list of files to process. Second, I parse the file path to generate the filename to be used for ...
2
votes
1answer
318 views

redirect awk exec results to another folder [duplicate]

Trying to capitalize the content of the files that match the filename pattern "_base.txt"; then output the results to another folder with the original filename plus the "_cap.txt" in the end. I plan ...
0
votes
0answers
388 views

PHP shell_exec to run debian system service

I'm trying to control a system service with PHP's shell_exec function : shell_exec('sudo /usr/sbin/service icecast2 stop'); But the only way I can get it to work is by allowing ALL users root access ...
7
votes
2answers
859 views

Echo to file descriptor overwrites the file?

I am having trouble understanding what is happening when I try to write to a file descriptor? It appears to be overwriting the original contents? Is this expected behaviour? I have replicated this in ...
0
votes
2answers
1k views

Eval and exec with variable substitution

I'd like to execute a statement to start a server. For that I have an environment variable to determine which server is to be started. I was given this command as a starting point: eval "exec ...
0
votes
1answer
500 views

What are differences between `do_execve()` and `_start` copying the command line arguments and environment?

Understanding The Linux Kernel says that execve() calls do_execve( ) which in turn copies the file pathname, command-line arguments, and environment strings into one or more newly allocated page ...
1
vote
1answer
458 views

How does `execve()` call a special start-up routine and the main() function?

When a C program is executed by the kernel—by execve(), where does execve() call a special start-up routine crt0 which is called before the main function is called? where does execve() call ...
0
votes
0answers
282 views

How does `execve()` pass command line arguments to `main()`? [duplicate]

How does execve(path, argv, envp) pass the command-line arguments in argv array and the environment envp array to the main function of the executable file being executed? Does it pass the address ...
4
votes
1answer
2k views

Using exec 3> to keep a named pipe open

The process reading from a named pipe will normally terminate when the process writing to the pipe finishes writing (sends an EOF). In certain situations you may have different processes writing ...
0
votes
2answers
71 views

How to delete directories based on `find` output: ONLY the first result

Based on this question, How to delete directories based on `find` output? I tried to remove only the first folder of result doing: find * -type d | head -n1 | -exec rm -rf {} \; But I receive ...
0
votes
1answer
510 views

Find, grep and then create table

I am trying to find all *.md at ${PWD}, then grep for lines beginning with title: and print it along with the absolute filepath -H and the line number of the pattern match -n, then I try to output the ...
-2
votes
1answer
81 views

Does the Linux kernel support a PARTIAL exec

I was looking at another question (https://stackoverflow.com/q/47845/537980), and saw an answer, about how much set up this other OS had to do, for every Process Create. I got wondering. Would it be ...

1
2 3 4 5