Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
Results 11 to 18 of 18
Like Tree8Likes
Code: ~$ sudo script1_start ~$ nohup: appending output to `nohup.out' ~$ ps -C script1 -o pid,ppid PID PPID "script1_start" starts "script1" with Code: nohup script1 &...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11
    Just Joined!
    Join Date
    Oct 2012
    Posts
    29

    Code:
    ~$ sudo script1_start
    ~$ nohup: appending output to `nohup.out'
    ~$ ps -C script1  -o pid,ppid
      PID  PPID
    "script1_start" starts "script1" with
    Code:
    nohup script1 &

  2. #12
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    226
    hmm
    Code:
    $ ls -l *background
    -rwxr-xr-x 1 root root 117  9 nov.  02:24 background
    -rwxr-xr-x 1 root root  37  9 nov.  02:20 start_background
    $
    $ cat start_background
    #!/bin/bash
    
    nohup ./background &
    $
    $ cat background
    #!/bin/bash
    
    echo $$ > /tmp/${0##*/}.pid_file
    while :
    do # any command
       sleep 10
    done
    $
    $ sudo ./start_background
    $ nohup: appending output to `nohup.out'
    $
    $ cat /tmp/background.pid_file 
    2573
    $
    $ sudo kill $(</tmp/background.pid_file)
    $
    no more background process
    pinhead likes this.

  3. #13
    Just Joined!
    Join Date
    Oct 2012
    Posts
    29
    Thanks for your effort.

    I think it doesn't work in my situation, because I am calling a script from within another script.

    Start script:
    Code:
    #!/bin/bash
    
    source main
    nohup main &
    echo "start script pid is "$$
    Main script:
    Code:
    #!/bin/bash
    
    echo $$ > /var/tmp/main.pid
    echo "message_listener pid is "$$
    Both scripts echo the same pid, but when I enter kill -9 with the pid that was echoed, I am getting the "No such process" error.

  4. $spacer_open
    $spacer_close
  5. #14
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    226
    why are you sourcing main?
    how come the scirpt is executed when you don't give its path (is the current directory in PATH? this is not a good idea)?

    of course two processes cannot have the same pid, that's the sourced script which outputs the pid of its current shell: the sart script!

    remove the useless source command.
    pinhead likes this.

  6. #15
    Just Joined!
    Join Date
    Oct 2012
    Posts
    29
    When I don't source main, it's not getting called. Both scripts are located at /usr/sbin.

    What I'm trying to achieve is a simple start script that puts the main script in the background.

  7. #16
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    226
    do simple things like I'm showing here.
    if it works, then adapt to your main script.
    otherwise put a trace in your scripts, like this
    Code:
    #!/bin/bash
    
    exec 2> /tmp/${0##*/}.log
    set -x
    
    #your code
    that will create logs for your scripts, and show what's done or not.

    main script is executable, right?
    pinhead likes this.

  8. #17
    Just Joined!
    Join Date
    Oct 2012
    Posts
    29
    That worked. Thanks for your help.
    I have found some interesting code that does exactly what I was looking for: https://gist.github.com/447191
    In the start function, this is happening:
    - Touch locks the pid file.
    - The nohup command starts a command that is represented by a variable. nohup can only call shell scripts and not single functions. From this follows
    that the command that is called by nohup, always has to be in a different file.
    Is my understanding right?

  9. #18
    Just Joined!
    Join Date
    Oct 2012
    Posts
    29
    One last question: Why can't I terminate a nohup-process? When I use kill -15 2730 , the kill command is completely ignored. kill -9 2730 works, but is bad style, so what choice do I have?

Page 2 of 2 FirstFirst 1 2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •