Skip to content

daemonized code is not running #15

@Android789515

Description

@Android789515

I have a strange issue where the code I wrote for a daemonized process to run is not running at all. I'm not getting an error, either.

Here is my code:

    println!("Test1");
    match daemon(false, false) {
        Ok(Fork::Child) => {
            let pid = getpid();

            let mut pid_file = File::create(PID_FILENAME)
                .expect("Unable to create the pid file");

            writeln!(pid_file, "{}", pid)
                .expect("Unable to write pid to file");

            println!("Test2");
            let shutdown_result = Command::new("sleep")
                .arg("30")
                .output();

            if let Err(reason) = shutdown_result {
                panic!("{reason}");
            }
        },
        Err(reason) => {
            panic!("{reason}");
        },
        _ => unreachable!(),
    }

I see Test1 output to stdout but I never see Test2 and the pid file is never created.

My mistake, ofc I wouldn't see Test2, but I still don't see the file being created.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions