Juve
Juve

Reputation: 10834

Generic ways to invoke syscalls from the shell

I like to call truncate(const char *path, off_t length) (see man 2 truncate) directly from the command line or in shell script.

I guess I could embed a C program and then compile, run, and remove it.

Another short alternative is using perl -e "truncate($file,$length)".

Questions:

Is perl -e "syscall(params...)" the most common pattern to invoke syscalls? How well does it cover other syscalls?

Is there another common way to invoke Linux/BSD syscalls from the shell? For instance, using a command like syscall "truncate($file,$length)"?

Upvotes: 2

Views: 441

Answers (1)

Juve
Juve

Reputation: 10834

Thank you for all comments and suggestions. I conclude the following answers to my questions:

  1. Some scripting languages, e.g., perl, may provide functions that resemble or wrap some of the useful syscalls, i.e., those that would make sense calling from the shell.
  2. However, there is no 1:1 mapping of scripting APIs and syscalls and no "common pattern" or tool to invoke many different types of syscalls from the shell.

Moreover, a generic solution for a specific problem should not focus on syscalls in the first place, but rather use a generic language or library from the beginning. For instance, for file truncation this may actually be perl, using perl -e "truncate($file,$length)".

Upvotes: 4

Related Questions