Shell Why does daemon -p not do what I expected?

If I ask daemon to write a pidfile, it does not run the app. How do I make it run the app and write a pidfile, as I expect? Sort is just a stand-in for a more complex app and is used to demonstrate my issue with daemon.
Code:
root@jenkins:~ # freebsd-version
13.4-RELEASE-p1
root@jenkins:~ # echo Contents > contents.txt
root@jenkins:~ # sort -o sortout.txt contents.txt
root@jenkins:~ # cat sortout.txt
Contents
root@jenkins:~ # rm sortout.txt
root@jenkins:~ # daemon sort -o sortout.txt contents.txt
root@jenkins:~ # cat sortout.txt
Contents
root@jenkins:~ # rm sortout.txt
root@jenkins:~ # daemon -p sort.pid sort -o sortout.txt contents.txt
root@jenkins:~ # cat sortout.txt
cat: sortout.txt: No such file or directory
 
Code:
root@jenkins:~ # daemon -p sort.pid sort -o sortout.txt contents.txt
What is the exit (return) code?

Code:
EXIT STATUS
     The daemon utility exits 1 if an error is returned by the daemon(3)
     library routine, 2 if child_pidfile or supervisor_pidfile is requested,
     but cannot be opened, 3 if process is already running (pidfile exists and
     is locked), 4 if syslog_priority is not accepted, 5 if syslog_facility is
     not accepted, 6 if output_mask is not within the accepted range, 7 if
     output_file cannot be opened for appending, and otherwise 0.
 
If the return code is 0 then it didn't fail. It might not have done what you expected but it didn't fail doing it.
 
If I ask daemon to write a pidfile, it does not run the app. How do I make it run the app and write a pidfile, as I expect? […]
I cannot reproduce your problem. For good measure, specify full pathnames and separate parameters to daemon(8) from the daemonized command and its arguments with a -- .​
Bash:
daemon -p /var/run/my_app.pid -- /usr/local/bin/my_app -o /tmp/output.txt /tmp/input_file_0 /tmp/input_file_1
 
Back
Top