Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm having trouble with sending shutdown -h 0 to a lxc Debian container (i.e. executing this command in the lxc) with with the python pexpect module (in a python script). In this module the user can "expect" (= wait for process output) a certain substring, amongst others EOF, which leads me to the question in order to be able to debug further why EOF isn't recognized in the output. I need to know what I can "expect" after termination of the process in order to wait for the process to end. I can't simply wait for the process because the pexpect module hides non-blocking functions for that.

The pexpect module (see http://www.bx.psu.edu/~nate/pexpect/pexpect.html#pexpect.spawn.expect for details) wraps the reception of EOF in the read system call in a (duck)type and makes it usable in pexpect.expect (an encapsulation of possible output/feedback of a process).

I've been wondering that because some processes like ls are expected to terminate with EOF, i.e. the pexpect sense of EOF (example at http://pexpect.sourceforge.net/pexpect.html).

share|improve this question
3  
I'm not sure about the expect part of your question, but in Unix, EOF is not something that you can write to stdout. It's not a character or byte sequence. When a process is reading bytes out of a file, it eventually will reach the end of that file, and the read syscall will return a special value to indicate that there's nothing more to read. This is an EOF condition. In the case of a pipeline, a writer process could close a file descriptor (using, eg, fclose(stdout)), and the reader would see that when calling read on stdin. –  godlygeek Jun 27 at 13:58
1  
Can you elaborate more on what exactly you're trying to do? If you were just trying to use python to execute shutdown -h now you'd be using the subprocess module, not pexpect - so what are you trying to get expect to do for you? –  godlygeek Jun 27 at 14:18
    
What process are you waiting to finish? If you're waiting for a shutdown -h now command to finish, you'll never see it - because the machine shuts down before the command finishes. –  godlygeek Jun 27 at 14:31
    
No I'm waiting for shutdown -h 0 executed in the Linux container lxc which causes the container to the shut down but not the machine it is running on!! –  Karl Richter Jun 27 at 14:59

2 Answers 2

Rather then running this shutdown -h 0 command I'd suggest running halt instead, or running this command from the host, lxc-shutdown -n <name>.

Source: 9.5 Monitoring and Shutting Down Containers

share|improve this answer
    
Thanks for your support on pexpect, it helped my, but didn't answer the question. I experienced no difference between halt and shutdown -h so far. As everything is working out after fixing the issue described in my answer, I didn't test lxc-shutdown -n. –  Karl Richter Jun 30 at 15:50
up vote 0 down vote accepted

EOF indicates that no further input is to be expected on a resource which possibly provides an endless amount of data (e.g. a stream). This situation is often expressed by writing a single character on the stream (to be defined by the underlying system (likely a OS or runtime environment )).

As processes use streams for inter-process communication they need to indicate the limits of their output and sending processes need to inidicate the limits of their input using EOF. The underlying system will very certainly forward this input and output to its own process handling mechanisms making EOF avaialble for evaluation in the program/on the system.

Note about pexpect use case in the question: shutil.pexpect doesn't seem to be suitable to copy files of a lxc container. It got stuck and the time offset of the pexpect output causes the confusion.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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