Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
Results 11 to 18 of 18
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11

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

  2. #12
    $ 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
    nohup ./background &
    $ cat background
    echo $$ > /tmp/${0##*/}.pid_file
    while :
    do # any command
       sleep 10
    $ sudo ./start_background
    $ nohup: appending output to `nohup.out'
    $ cat /tmp/background.pid_file 
    $ sudo kill $(</tmp/background.pid_file)
    no more background process

  3. #13
    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:
    source main
    nohup main &
    echo "start script pid is "$$
    Main script:
    echo $$ > /var/tmp/
    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
  5. #14
    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.

  6. #15
    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
    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
    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?

  8. #17
    That worked. Thanks for your help.
    I have found some interesting code that does exactly what I was looking for:
    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
    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?

Posting Permissions

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