OS system calls from bash script

偶尔善良 提交于 2019-12-21 04:35:15

问题


Is it possible to call os system calls like open, close etc from a shell script? I tried googling but it takes me in the wrong direction of using "system()" command. Can some one help on this?


回答1:


Many syscalls are accessible, but only via the native shell mechanisms, rather than being able to directly specify exact parameters. For instance:

exec 4>outfile

calls:

open("outfile", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3
dup2(3, 4)

(with 3 being replaced by the next available descriptor), and

exec 4<&-

calls:

close(4)

Some shells, such as bash, allow additional builtins to be added through loadable modules (see the enable builtin, used to load such modules); if you really needed functionality not provided upstream, you could potentially implement it that way.



来源:https://stackoverflow.com/questions/10196395/os-system-calls-from-bash-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!