Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I need to send data to a Linux terminal, in this manner that terminal could receive the data with scanf? there is any way to do that?
I tried to write my desired data to /proc/pid/fd/1 with below command, however, I can see the written data in the terminal but scanf couldn't catch that data and still wait for the user to enter data.
printf "85\n" > /proc/24737/fd/1
This is a very interesting question, and there is no easy way (that I know of) to write to a another terminal using the file descriptors.
see https://unix.stackexchange.com/questions/385771/writing-to-stdin-of-a-process
However, Unix and Linux, have many great ways for IPC (inter process communication). You might want to looking into pipes, named pipes, or Sockets.
Depending on what you are doing you might think about popen, or screen.
You probably don't want to write to the terminal, but the task that is running on the terminal? Can you change how the task is invoked (called)? Do you need to use standard in for other things?
If you explain your use case, we will try to direct you better.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed last year.
Improve this question
I would like a command-line-tool to fail if it opens a particular file for writing.
Is there a way I can modify the environment (maybe via cgroups) of the command-line tool, so that the command/process gets (for example) "permission denied"?
chmod a-w file does not work. The process seems to unlink() and then re-create the file.
I know that I can watch the syscalls of a process with strace. But is there a way to alter some calls, so that the process gets a different result?
Background: unittesting
strace has an option called -e inject or simply --inject which can be used to alter system calls of the tracee. (See manpage here)
In particular, in can be combined with the -P option to only trace syscalls accessing a specified path.
Since the calls are honored in the order they are loaded from shared libraries, you can use LD_PRELOAD to load a custom library prior to the system libraries and hijack their execution. This is used by many network card accelerators like OpenOnload from Solarflare/Xilinx.
https://sumit-ghosh.com/articles/hijacking-library-functions-code-injection-ld-preload/
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I have program that I need to run and then see how much resources it uses in unix by using top command. But I don't know how to do it because if i run it from command line I cant use top command till program is finished and vice versa. How can I do it. I tried doing:
sleep 10s
top
./myProgram
But its not working
Open two terminals; run your program in one terminal and top in another.
If you're in a graphical environment, you can just start the terminal a second time.
If you're on the text-only console, you can switch between terminals using Ctrl-Alt-F1..F6 (possibly more) or Alt-Left/Right.
If you connect via SSH, just open multiple terminal sessions in your SSH client.
(Also, I'd hint to use htop instead of top, but you may need to install it first.)
In case your program is too short-lived to show up on top/htop, you might need to run it using Valgrind.
Open two terminals one for running top, and run your program in the other.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
I read, some years ago, that you could get linux to invoke the java command to run java programs by adding a bit of linux magic, but I can't remember how to do it or where I read it.
Back then I got it working and, if I recall correctly, it was fairly easy to do; just tell linux to use java to run .jar or similar files. I believe I also got it to run powerpc binaries, through qemu, using the same technique. Naturally, you would still have to mark them as exeutable.
I am not talking running java java_program_to_run or using some shell script that will, essentially, just call the same command. Nor am I asking for a way to convert a java program to an x86 binary for any particular operating system.
It was a technique that would allow Linux to deal with exectuables that wheren't native to the system, almost, as if they where native (some simulation required).
You want to checkout binfmt. More specifically, follow the instructions for java. I realize the usual practice is to copy the details into the answer, but they're quite long and it doesn't feel right to copy-and-paste the whole thing into the answer.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
I want to ask something that just came to my mind. I search google and stackoverflow and couldn't find a answer to my question, if there is any, please inform me.
Is it possible to bind a process to a combination of key strokes? For example, can i start my program with simply pushing the buttons ctrl + k or it can be any other function keys. Is it possible to start a process like that? I know that i must compile kernel and boot up again if it is possible but i couldn't find the place where the meaning of key combinations stored.
Thanks for helping.
you can use bind for this, i.e. to run pwd when F12 is pressed
bind '"\e[24~":"pwd\n"'
move program you want to run to /usr/bin or another directory in the stadard path use the path in the bind command
bind '"\e[24~":"absolute_path_to_program/program"'
https://unix.stackexchange.com/questions/89622/how-to-execute-a-script-in-shell-when-a-shortcut-key-is-pressed
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I would like to execute "lessc ~/less/app.less > ~/stylesheets/styles.css" everytime I modify a .less file on my machine. Is it possible ?
If you are looking for a generic approach, Linux kernel has a feature called inotify that monitors file system changes.
You will have to write a small program to make use of the interface. inotify has bindings for all major languages, including perl and python .
Take a look at incron, a crontab-like system for inotify. You can set up rules to trigger any commands you want, based on events in the filesystem.