0

When I tried to change from super user to common user and therefore typed "exit", I got an error message, that a job was stopped and I could not log out as root. So I listed the jobs:

#jobs
[1]+ yes | apt-get install build-essential

I moved the job from the shells background to foreground

fg 1

now I thought, I could simply press ctrl+c to end it, but each time I pressed ctrl+c, nothing happened except for "^c" being displayed. When I pressed ctrl+z I came back to the prompt, but the job was still there, so I was caught in the # .

  • 2
    I don't think fg 1 is correct. Why are you using 1 there? Just fg should work. You can just kill the job. kill processname. – Faheem Mitha Mar 16 '15 at 12:11
  • I did not know I could use kill command with a processname, I used it only with PID. – Abdul Al Hazred Mar 16 '15 at 12:28
  • By processname, I meant the process id. And apt-get should normally be interruptible with Ctrl-C. – Faheem Mitha Mar 16 '15 at 13:14
3

^C generates an interrupt signal (SIGINT). It's allowable for programs to mask this signal, and either ignore it completely or 'react' to it in a non fatal way.

For example - you might want a program to stop whatever it's doing right now, but without terminating completely.

So ^C doesn't always work.

^Z to stop the job, and then kill %1 (where %1 is the number on the jobs list) will sent it a terminate signal (SIGTERM) instead which should do the trick.

  • strangely, I still could not log out after ctrl+z though the shell itself was not occupied with the job the moment i sent the SIGTERM. there was still the [1]+ job entry after SIGTERM. – Abdul Al Hazred Mar 16 '15 at 13:28
  • Yes, that's normal - a stopped process can block a logout. You might need to fg the process again, so it can resume and exit. – Sobrique Mar 16 '15 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.