How to check if a file is open in editor?


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to check if a file is open in editor?
# 22  
Old 10-19-2017
Quote:
Originally Posted by Don Cragun
OK. I don't have leafpad or gedit on my system. When testing with vi (note that in post #10, the O.P. said that gedit and vi were used interchangeably), by running the command line:
Code:
vi somefile& PID=$!; sleep 10; jobs $PID; sleep 10; fg $PID

I immediately get:
Code:
vi somefile& PID=$!; sleep 10; jobs $PID; sleep 10; fg $PID
[1]    83379

and about 10 seconds later I get:
Code:
[1] + Stopped (SIGTTOU)        vi somefile& PID=$!; sleep 10; jobs $PID; sleep 10; fg $PID

noting that vi is stopped; not terminated. And about 10 seconds later, the fg $PID brings vi somefile into the foreground so I can edit somefile. When I quit vi, I then get a new shell prompt for another command.
When I attempted this, with identical code except I use gedit rather than vi it returned:
Code:
gedit Repository.sh & PID=$!; sleep 10; jobs $PID; sleep 10; fg $PID
[1] 24318
[1]+  Done                    gedit Repository.sh
bash: jobs: 24318: no such job
bash: fg: 24318: no such job

Saying that there is no such job? What do these errors mean?
# 23  
Old 10-19-2017
Quote:
Originally Posted by cherryTango
When I attempted this, with identical code except I use gedit rather than vi it returned:
Code:
gedit Repository.sh & PID=$!; sleep 10; jobs $PID; sleep 10; fg $PID
[1] 24318
[1]+  Done                    gedit Repository.sh
bash: jobs: 24318: no such job
bash: fg: 24318: no such job

Saying that there is no such job? What do these errors mean?
It means that gedit terminated in the 10 seconds before the jobs command started running. Under normal circumstances, it would also mean that you issued another command in those 10 seconds to reap the exit status of gedit (such as wait $PID or wait without an operand) before the jobs command started running.

Does gedit start an editing session in your current window (like vi does) or does it start an editor in a new window? If it starts it in a new window, do you get a new shell prompt in your shell window immediately after typing in the command:
Code:
gedit Repository.sh

or do you not see a new shell prompt until that editing window closes?

What operating system are you using?

Last edited by Don Cragun; 10-19-2017 at 06:35 PM.. Reason: Fix typo.
This User Gave Thanks to Don Cragun For This Post:
# 24  
Old 10-20-2017
When I input
Code:
gedit Repository.sh

into the terminal it will open the text editor in another window, unless I have already got a file open in gedit by using
Code:
Applications > Text Editor

When there is not already a file open I must close that file in order to use the terminal again. However if there is a file open I can continue to use the terminal immediately after typing
Code:
gedit Repository.sh

I am using Ubuntu 17.04.

---------- Post updated at 02:25 AM ---------- Previous update was at 02:14 AM ----------

Just to clarify - I'm not typing "Applications > Text Editor" into the terminal. That's just the 'clicks' I make to open it.

---------- Post updated at 10:11 AM ---------- Previous update was at 02:25 AM ----------

Hi all! Today I decided I would use the 'Bash in Windows' BETA and I've moved all my files onto that and for whatever reason all the previous examples that rely on the PID have worked! Currently I am using:
Code:
DISPLAY=:0 gedit "$1" & PID="$!"
			while : 
			do
			sleep 1
				if [ -x /proc/$PID ]; then
					clear
					tput cup 2 5 ; echo -e "${RED}           Can not update log until editor is closed!           ${NC}"
					tput cup 3 5 ; echo -e "${boldon}Please finish editing your file and close gedit.${boldoff}"
				else
					clear
					updateLog
				fi
			done

And it works perfectly! Thank you everyone that helped!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To check if a file is open and in use (logs are being written to it)

Hello Experts, I need to write a shell script to check if a file is open and something is being written to it. I want to know how OS handles it. I checked with lsof command but it is not working. For a test I did this. while true; do echo `date` >>abc.txt; done then I checked lsof |... (5 Replies)
Discussion started by: shekhar_4_u
5 Replies

2. Shell Programming and Scripting

Not able to read .csv file until open in vi editor

Hi, I am facing a problem regarding .csv file, my script does not read .csv file and if i open this file in vi editor and perform :wq option then only my script reads the .csv file. Thanks (5 Replies)
Discussion started by: ranabhavish
5 Replies

3. UNIX for Dummies Questions & Answers

Vi editor will not open new to UNIX. help please.

vi: syntax error at line 1: `)' unexpected when I try to vi into the /etc/vfstab, the return gives me the above error. how can resolve this so that I can have access into vi. (6 Replies)
Discussion started by: dovestar
6 Replies

4. UNIX and Linux Applications

Notepad++ hang when open file edited in other text editor

Hi, I would like to ask about the notepad++ text editor application, Although there are alternative and more great text editor in linux (gedit, geany, jedit) im still using the notepad++ sometimes cause for some of my own reason one of those is the minimalist text(what i mean is notepad++ has a... (2 Replies)
Discussion started by: jao_madn
2 Replies

5. Solaris

Before I delete any file in Unix, How can I check no open file handle is pointing to that file?

I know how to check if any file has a unix process using a file by looking at 'lsof <fullpath/filename>' command. I think using lsof is very expensive. Also to make it accurate we need to inlcude fullpath of the file. Is there another command that can tell if a file has a truely active... (12 Replies)
Discussion started by: kchinnam
12 Replies

6. Shell Programming and Scripting

avoid open file to check field.

Hi Everyone, # cat a.txt 94,aqqc,62345907, 5,aeec,77, # cat 1.pl #!/usr/bin/perl use strict; use warnings; use Date::Manip; open(my $FA, "/root/a.txt") or die "$!"; while(<$FA>) { chomp; my @tmp=split(/\,/, $_); if (index($tmp, "qq") ne -1) { ... (4 Replies)
Discussion started by: jimmy_y
4 Replies

7. UNIX for Dummies Questions & Answers

How to open file in VI Editor at a specific line?

i have following query e.g i want the VI Editor cursor at line number N instead of 0 while opening the file from unix prompt. vi filename ?????? Can anyone help? (4 Replies)
Discussion started by: skyineyes
4 Replies

8. UNIX for Advanced & Expert Users

getting error when open vi editor

helo I install my product for koren language I m uisng RHEL -4 operating system now problem is whenever I open any file vi filename I got following error on the screen E557: Cannot open termcap file 'vt100' not known. Available builtin terminals are: builtin_ansi ... (1 Reply)
Discussion started by: amitpansuria
1 Replies

9. Shell Programming and Scripting

How to give permissions to an open file in vi editor?

Hi all, I have a shell script that i started editing, only in the midst of which i tried to save the changes i found that the file wasnt been provided with write/execute permissions. I later have redone the changes and saved the file- Just curious to know if there was any command wherein... (5 Replies)
Discussion started by: Pankajakshan
5 Replies

10. UNIX for Advanced & Expert Users

Unable to open files in VI editor

Hi, I unable to open any file using Vi editor,constantly getting the following error, vi log.log *** glibc detected *** malloc(): memory corruption: 0x081af510 ** uname -a Linux sekac092 2.6.5-7.244-bigsmp #1 SMP Mon Dec 12 18:32:25 UTC 2005 i686 athlon i386 GNU/Linux Also Note ls... (8 Replies)
Discussion started by: ennstate
8 Replies
Login or Register to Ask a Question