# Sequential Process execution question

**URL:** <https://community.seqera.io/t/sequential-process-execution-question/2240>\
**Category:** Ask for help\
**Created:** [June 27, 2025, 6:02pm UTC](https://community.seqera.io/t/sequential-process-execution-question/2240 "2025-06-27T18:02:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephen\_mclaughlin](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/stephen_mclaughlin/32/1885_2.png) [@stephen\_mclaughlin](https://community.seqera.io/u/stephen_mclaughlin)\
**Post date:** [June 27, 2025, 6:02pm UTC](https://community.seqera.io/t/sequential-process-execution-question/2240/1 "2025-06-27T18:02:56Z")

</div>

Hi community -

I’m having trouble figuring out what the best way might be to handle this in Nextflow and somehow i never came upon this issue before:

Let’s say I have process1, process2, and process3 where process2 is dependent on the output of process1 and process3 is dependent on the output of process2. And let’s say the input to process1 has 10 elements (so process1 gets executed 10 times).

What i’m looking to avoid is process1 running 10 times in a row without executing process2 and process3; I’d like process2 and process3 executed first before it moves onto the second call of process1.

Is there a feature that would handle this in Nextflow or a recommended best practice for dealing with this situation?

Best Regards,  
Steve

Edit: I’m already hip to maxForks but it still doesn’t stop 10 sequential process1 calls. process1 is downloading a lot of data and i was hoping to have it deleted after some downstream stuff runs.

---

<div class="post-metadata">

**Author:** ![mribeirodantas](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/mribeirodantas/32/235_2.png) [@mribeirodantas](https://community.seqera.io/u/mribeirodantas)\
**Post date:** [August 29, 2025, 1:22pm UTC](https://community.seqera.io/t/sequential-process-execution-question/2240/2 "2025-08-29T13:22:19Z")

</div>

Hi @stephen_mclaughlin,

I’m not sure if I understood what you’re looking for, as `maxForks` should help you with that. See the snippet below:

```auto
process FOO {
  maxForks 1
  debug true                                                                                                                                                                                   

  input:
  val ch_input

  output:
  val 'oi'

  script:
  """ 
  echo 'FOO ${ch_input}'
  sleep 5
  """ 
}

process BAR {
  debug true

  input:
  val some_input

  script:
  """ 
  echo 'BAR ${some_input}'
  sleep 5
  """ 
}

workflow {
  ch = Channel.of(1..10)
  FOO(ch)
  BAR(FOO.out)
}

```

I can’t upload a video here, but every time a FOO task was finished, a BAR task started. If you run the code above on your machine, you should see `FOO 2 of 10` and `BAR 1 of 10`. `FOO 3 of 10` and `BAR 2 of 10`, and so on.

 ![Screenshot 2025-08-29 at 10.24.05](https://europe1.discourse-cdn.com/flex013/uploads/seqera/original/2X/6/6295e473135b4649560923a082a1d0059757378c.jpeg)

See:

 ![Screenshot 2025-08-29 at 10.22.55](https://europe1.discourse-cdn.com/flex013/uploads/seqera/original/2X/6/628c623eba79d4d4e55210c3a2b6211fc4c61274.jpeg)

---

<div class="post-metadata">

**Author:** ![stephen\_mclaughlin](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/stephen_mclaughlin/32/1885_2.png) [@stephen\_mclaughlin](https://community.seqera.io/u/stephen_mclaughlin)\
**Post date:** [August 29, 2025, 2:48pm UTC](https://community.seqera.io/t/sequential-process-execution-question/2240/3 "2025-08-29T14:48:41Z")

</div>

Hi Marcel,

Thanks for the reply! Maybe you’re right that maxForks will help me, but it didn’t seem that way to me at the time I wrote this up. What I was interested in doing is downloading some large files in process1, performing some operations on them in multiple processes (i.e. process2-6) and finally deleting them by process7 because they are so large that if too many accumulate my diskspace fills up. Since there’s some benefit in processing them simultaneously as I have multiple processors (I’m running Nextflow in local mode with 8 CPU) I wanted to parallelize them in batches i.e. 8 files at a time. Is it the cases that if each process had maxForks 8 I could achieve this goal? It’s a bit unclear to me what effect that would have on the sequence of process execution. I was under the impression maxForks 1 would prevent more than 1 of the FOO processes from running simultaneously, but wouldn’t necessarily have an effect on the sequence of execution which would be mostly up to random chance. Is that a misunderstanding of maxForks on my part?

Best,  
Steve

---

<div class="post-metadata">

**Author:** ![mribeirodantas](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/mribeirodantas/32/235_2.png) [@mribeirodantas](https://community.seqera.io/u/mribeirodantas)\
**Post date:** [September 3, 2025, 2:30pm UTC](https://community.seqera.io/t/sequential-process-execution-question/2240/4 "2025-09-03T14:30:45Z")

</div>

If you set `cpus 8`, depending on your compute environment (e.g., a cluster with a workload manager), Nextflow will try to use these 8 CPUs if required. If you want to limit the parallelization of tasks _per process_, you use `maxForks`. If you want to control order (make sure the first process instance, a task, finishes first, then the second, and so on, also known as fair threading), you use the `fair` process directive.

As for cleaning the work directory (downloaded files), the only native option we provide for now is `cleanup` upon finishing the run successfully, which is not very helpful for you. However, the [nf-boost plugin](https://github.com/bentsherman/nf-boost) offers cleaning up the work directory on the fly and is exactly what you need to fight this disk usage situation.

Two other things that may be useful to you: Whenever you want to control process flow that is not tightly input-output linked, you can use [value signals (or state dependency)](https://nextflow-io.github.io/patterns/state-dependency/). If, for some reason, you want to handle multiple samples (or tasks) in a single task (process instance), you can use [task batching](https://nextflow-io.github.io/patterns/task-batching/). Task batching is useful when you need to move lots of files because tasks are run in different places. By running a bunch of them together, you decrease the number of downloads of files moving around in a cloud environment.

Not saying all this is useful for this specific situation you’re in, but I think it’s worth presenting them so that you can see what fits better your case.

---

<div class="post-metadata">

**Author:** ![stephen\_mclaughlin](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/stephen_mclaughlin/32/1885_2.png) [@stephen\_mclaughlin](https://community.seqera.io/u/stephen_mclaughlin)\
**Post date:** [September 4, 2025, 3:30pm UTC](https://community.seqera.io/t/sequential-process-execution-question/2240/5 "2025-09-04T15:30:10Z")

</div>

Appreciate the tips! I did end up using task batching to process things in groups and delete when i was done, but I had a monolithic process `do_everything` to make sure I could download –\> process –\> and delete in batch sizes that were managable for diskspace. Not ideal or very elegant, but I still got my job done and benefited from Nextflow job reuse since it ran for 9+ days and needed to be interrupted several times. I’ll consider these other solutions for when I do something like this again.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/system/32/2402_2.png) [@system](https://community.seqera.io/u/system)\
**Post date:** [September 11, 2025, 3:30pm UTC](https://community.seqera.io/t/sequential-process-execution-question/2240/6 "2025-09-11T15:30:32Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
