Results 1 to 5 of 5

Thread: my own sleep program vs the sleep command

  1. #1
    Join Date
    Jan 2010
    Location
    Wheeling WV USA
    Beans
    1,567
    Distro
    Xubuntu 18.04 Bionic Beaver

    my own sleep program vs the sleep command

    i wrote my own sleep program and bash behaves different with it than it does with the sleep command. could it be a secret built-in command? the bash man page has no references to "sleep" whatsoever. the different behavior is when my program (named "nsleep") runs before another on one command line ("nsleep 999999;date") and ctrl-C is pressed. with my nsleep the date command is run anyway. with the standard sleep command, date is not run. bash is doing it different. what causes this? is bash getting a special signal? is bash treating sleep differently?
    Code:
    lt2a/forums /home/forums 2> sleep 999999;date
    ^C
    lt2a/forums /home/forums 3> nsleep 999999;date
    ^CSat Dec 14 20:17:40 EST 2019
    lt2a/forums /home/forums 4>
    What do you call someone who speaks 3 languages? Trilingual.
    What do you call someone who speaks 2 languages? Bilingual.
    What do you call someone who speaks 1 language? American.

  2. #2
    Join Date
    Nov 2011
    Location
    /dev/root
    Beans
    Hidden!

    Re: my own sleep program vs the sleep command

    At least in 18.04.x LTS sleep is an executable program (compiled, ELF can be seen at the head of the file /bin/sleep. You find some details via

    Code:
    man sleep
    and it is possible to find its source code. I guess there is nothing to trap the interrupt. You can compare with the shell built-in read

    Code:
    read -st5 -n1 ; date
    that behaves like sleep för ctrl+C but differently if you stop it gracefully with for example Enter.
    Last edited by sudodus; December 15th, 2019 at 03:01 AM.

  3. #3
    Join Date
    Jan 2010
    Location
    Wheeling WV USA
    Beans
    1,567
    Distro
    Xubuntu 18.04 Bionic Beaver

    Re: my own sleep program vs the sleep command

    sleep has always been a binary executable in ever Unix/BSD/Linux system i have ever used on every architecture. my nsleep is also a binary executable that has been built successfully, and run OK, on a few Linux distros and also on OpenBSD. i have seen this behavior on Slackware Linux (32 bit and 64 bit), Timesys Linux on an ARM based eval board (32 bit only), and on Ubuntu Linux (64 bit only) (every LTS since 14.04. i have not tried it on others for various reasons.

    if i use && instead of ; then date does not run for both programs being interrupted. i am considering writing a new version in Python3.
    What do you call someone who speaks 3 languages? Trilingual.
    What do you call someone who speaks 2 languages? Bilingual.
    What do you call someone who speaks 1 language? American.

  4. #4
    Join Date
    Nov 2011
    Location
    /dev/root
    Beans
    Hidden!

    Re: my own sleep program vs the sleep command

    I understand the different behaviour with regard to ctrl+C, but do not understand what you want, why you want your own sleep. Please explain.

  5. #5
    Join Date
    Jan 2010
    Location
    Wheeling WV USA
    Beans
    1,567
    Distro
    Xubuntu 18.04 Bionic Beaver

    Re: my own sleep program vs the sleep command

    the why of my own sleep command is another topic for another thread.
    What do you call someone who speaks 3 languages? Trilingual.
    What do you call someone who speaks 2 languages? Bilingual.
    What do you call someone who speaks 1 language? American.

Bookmarks

Posting Permissions

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