-
-
Notifications
You must be signed in to change notification settings - Fork 625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
&
at the end of cmd
doesn't run the command in background
#928
Comments
ok so, I found the problem basically the task ends before the server can start may be we should add the support for |
This appears to be an issue with mvdan/sh. See replication steps below:
#!/bin/bash
for i in {1..5}; do sleep 1s && echo "$i"; done
Creates the file
Does nothing :/ |
I think the problem is that the parent task ends and it forces the child process created using |
I don't think this is to do with Task. As I said, this problem also exists when executing your command directly with Also, if we write a Taskfile like this: version: '3'
tasks:
sleep-5s-bg:
cmds:
- sleep 5s &
ps:
cmds:
- ps and then run
task: [ps] ps
PID TTY TIME CMD
...
416575 pts/1 00:00:00 task
416583 pts/1 00:00:00 sleep You can see that the task executes This appears to only be a problem with combining redirection ( |
I was able to reproduce the issue without using redirection. This task does not start dolphin by some reason. dolphin:
cmds:
- 'dolphin . &' The workaround is appending some dummy command to the main one. dolphin:
cmds:
- 'dolphin . &'
- ':' |
Ran into this starting up an express process in the background. |
I also ran into this issue, but none of the workarounds seem to work consistently (adding a dummy |
I was just about to create my first task and stumbled across this problem. I have now actually invested 2 hours to find the error, as I never thought that it was due to the task file or the interpreter. Unfortunately, the workaround with |
Would it be possible to |
I tried this, and I couldn't get the pid without using a sub-subshell (not sure why?), and since the defer tasks are run in a different subshell, it's not possible to wait for it. version: 3
tasks:
default:
cmds:
- mkdir -p run
- for: [chicken, duck]
task: process-item
vars:
ITEM: '{{.ITEM}}'
process-item:
cmds:
- |
sh -c 'sleep 30 &
echo $! > run/{{.ITEM}}'
- echo {{.ITEM}}
- defer: bash -c "wait $(cat run/{{.ITEM}})"
Output:
|
Okay, I discovered the reason we can't get the pid: mvdan/sh#221
|
It works if you run in bg both the subcommand in the subshell and the subshell itself, followed by sleep: task test_bg
task: [test_bg] bash -c 'sleep 10 & echo "PID $!"'& sleep 1
[test_bg] PID 4213
ps -fp 4213
UID PID PPID TTY STIME COMMAND
cri 4213 1 cons1 12:33:17 /usr/bin/sleep or, simpler, no PID output: task test_bg
task: [test_bg] $(sleep 10&)& sleep 1
ps -ef| grep sleep
cri 4367 1 cons1 12:43:49 /usr/bin/sleep Tested on both Windows and Linux. See #162 |
what is the solution to spawn a disowned process ? |
@leobenkel this worked for me: start-ollama:
cmds:
- bash -c 'nohup ollama serve >/dev/null 2>&1 &' |
I think this needs to be implemented as feature |
when using
&
at the end of a command doesn't make it a background task.latest
The text was updated successfully, but these errors were encountered: