So I asked chatgpt a question for an experimented Linux system administrator.

The question

Here is the question:

You are a software engineer and linux system administror. You are an expert in using shell script.
can you compare the following 3 ways to execute the command sleep 1200:
sleep 1200 &
nohup sleep 1200 &
(sleep 1200 &)

ChatGPT’s answer

After having given a detailed answer partly correct (there was one wron assertion), chatgpt added the following comparison which contains a totally wrong assertion:

This is totally wrong (sleep 1200 &) survives shell exit!!!

And it is the main reason why to use this syntax, so it is a big error from chatgpt to assert the opposite.

Also in its detailed answer, I can quote the following from chatGPT that details the behavior of (sleep 1200 &): “The process runs independently of the parent shell but is still subject to termination if the parent shell exits.”

So of course, this is wrong and it states the same error like inside the comparison table.

My answer (the good answer!?, but maybe not the more detailed one)

Firstly, do you now the answer? because you must know that the last command syntax is very useful for a system administrator.

sleep 1200 &

spawn the command sleep 1200 in a background process

nohup sleep 1200 &

do the same as sleep 1200 &, but prevent the background process to catch de SIGHUP signal, the background process won’t stop if it received SIGHUP signal. SIGHUP signal can be spawn with kill -SIGHUP command or when you close your terminal the SIGHUP signal is automatically send to each process attached to your terminal process.

Usually when a process received SIGHUP it stops.

(sleep 1200 &)

Here this is completely different from the two others. And it’s there that ChatGPT is not enough “intelligent” to know the difference.

This command spawn sleep 1200 in another shell that is not attached to the current shell. Here a process is spawn in a totally independant shell. Then if you close your terminal, I mean your current shell, the SIGHUP signal won’t reach the process that executes sleep 1200 because the process is in a different shell that is no child shell of your current shell.

Why ChatGPT asserts a wrong answer

Here are some suppositions.

Firstly, if you dig in internet it’s difficult to find a topic about the following syntax (<yourcommand> &).

Secondly, ChatGPT is almost always affirmative.

It’s a big difference with humans, when they have doubt, when we feel we are missing something, we are not affirmative. We can answer “I don’t know” or “I think that… but I’m not sure”.
Currently it’s not the case for chatgpt.


This is why it is preferable to have a good knowledge of the subject for which you are asking chatgpt. That way you can maintain a critical eye.

For your information: ChatGPT full answer (!!!careful, wrong assertion from chatgpt!!!)

Just for your information, here is the full answer of chatgpt.

Conclusion

ChatGPT is a very good tool, but it is preferrable to have good knoledge about the topic on which you are asking questions!

Don’t stop using it, it’s a revolution. But stay critical!