I am trying to develop a simple way to get the pid of a process once it is started. If you start a process in background with the "&", you then get its pid in stdout. But if I run this in a script, let's say a script called "test":
When I run this script, I would expect to get in the file test.log the same information as I get in stdout when I just run "sleep 60 &", which includes the pid.
Well, unfortunately the test.log is desperately empty, even if it is created.
Can someone tell me why?? Or any solution to automatically get the pid of a process, once it is started in a script? (I am not talking about manually doing "ps -ef" and grep, etc, etc, I am looking for something straight and simple.)
Code:
#!/bin/bash
sleep 60 & > test.log 2>&1
Well, unfortunately the test.log is desperately empty, even if it is created.
Can someone tell me why?? Or any solution to automatically get the pid of a process, once it is started in a script? (I am not talking about manually doing "ps -ef" and grep, etc, etc, I am looking for something straight and simple.)