fork和exec在bash

编程入门 行业动态 更新时间:2024-10-12 08:21:04
本文介绍了fork和exec在bash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何实现fork和exec在bash?

How do I implement fork and exec in bash?

让我们假设脚本

echo "Script starts" function_to_fork(){ sleep 5 echo "Hello" } echo "Script ends"

基本上我想该功能被称为C一样,我们使用fork和exec调用新的进程。

Basically I want that function to be called as new process like in C we use fork and exec calls..

从脚本预期母体脚本将结束,然后在5秒钟后,你好被打印。

From the script it is expected that the parent script will end and then after 5 seconds, "Hello" is printed.

推荐答案

使用的符号,就像你从shell会。

Use the ampersand just like you would from the shell.

#!/usr/bin/bash function_to_fork() { ... } function_to_fork & # ... execution continues in parent process ...

更多推荐

fork和exec在bash

本文发布于:2023-10-09 05:34:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1474848.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:fork   exec   bash

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!