- How to know boot time on Ubuntu
- 4 Answers 4
- Find Out How Long Does it Take To Boot Your Linux System
- Checking boot time in Linux with systemd-analyze
- Bonus Tip: Improving boot time
- Linux Uptime Command
- How Does the Uptime Command Work?
- Example 1: Uptime in Human-Readable Format
- Example 2: Check the Start Time of the System
- Example 3: Check the Version of the Installed Uptime Command
- Conclusion
- About the author
- Syed Minhal Abbas
- start time of a process on linux
- 1 Answer 1
- How to determine boot time?
- 4 Answers 4
How to know boot time on Ubuntu
How to get via terminal log of system boot time for last month. I tried to use last boot command, bit it returned information from the beginning of month.
4 Answers 4
I know Ubuntu has systemd now, but I haven’t tested this out on Ubuntu. If you have systemd then the following command should work.
If you are trying to increase boot performance then you might want to look at the output of
In Ubuntu the file /var/log/wtmp ( last gets data from this file by default) is rotated by logrotate following this configuration :
As you can see it will be rotated monthly, with only one rotational file will exist meaning /var/log/wtmp will contain current month’s logs while /var/log/wtmp.1 will contain previous month’s logs. No logs prior to that will be saved. you can change this configuration to suite your need if you want.
Now while you run last command you will see current month’s logs as the file /var/log/wtmp is read by last by default. As we know that the previous month’s logs are saved in /var/log/wtmp.1 , we can tell last to read from that file using -f option :
Same goes for the /var/log/btmp file while using lastb .
Another alternative to retrieve the system boot date consist using vmstat(8) in statistics mode with —stats argument.
The command expose the following line:
So the line can be parsed with gawk(1) and the timestamp can be converted using the date(1) command to a human readable format with the command below:
$ TIMESTAMP=$(vmstat --stats | awk '/boot time/') $ date -d @$TIMESTAMP or $ date -d @$(vmstat --stats | awk '/boot time/')
And another alternative, by using dmesg(1) with the -T argument to render the timestamp in human readable format and search for the Command Line pattern.
The Command Line pattern line indicate the Kernel boot command line and the timestamp in the kernel ring buffer which gives the system boot time:
$ dmesg -T|grep -i 'Command line'|head -1
These approachs will work on every Linux systems, not only Ubuntu distribution. Finally, the best portable way is using who -b has mentioned previously because it’s portable across systems such as Linux, Unix, OSX and FreeBSD.
Find Out How Long Does it Take To Boot Your Linux System
When you power on your system, you wait for the manufacturer’s logo to come up, a few messages on the screen perhaps (booting in insecure mode), Grub screen, operating system loading screen and finally the login screen.
Did you check how long did it take? Perhaps not. Unless you really need to know, you won’t bother with the boot time details.
But what if you are curious to know long long your Linux system takes to boot? Running a stopwatch is one way to find that but in Linux, you have better and easier ways to find out your system’s start up time.
Checking boot time in Linux with systemd-analyze
Like it or not, systemd is running on most of the popular Linux distributions. The systemd has a number of utilities to manage your Linux system. One of those utilities is systemd-analyze.
The systemd-analyze command gives you a detail of how many services ran at the last start up and how long they took.
If you run the following command in the terminal:
You’ll get the total boot time along with the time taken by firmware, boot loader, kernel and the userspace:
Startup finished in 7.275s (firmware) + 13.136s (loader) + 2.803s (kernel) + 12.488s (userspace) = 35.704s
graphical.target reached after 12.408s in userspace
As you can see in the output above, it took about 35 seconds for my system to reach the screen where I could enter my password. I am using Dell XPS Ubuntu edition. It uses SSD storage and despite of that it takes this much time to start.
Not that impressive, is it? Why don’t you share your system’s boot time? Let’s compare.
You can further breakdown the boot time into each unit with the following command:
This will produce a huge output with all the services listed in the descending order of the time taken.
7.347s plymouth-quit-wait.service 6.198s NetworkManager-wait-online.service 3.602s plymouth-start.service 3.271s plymouth-read-write.service 2.120s apparmor.service 1.503s [email protected] 1.213s motd-news.service 908ms snapd.service 861ms keyboard-setup.service 739ms fwupd.service 702ms bolt.service 672ms dev-nvme0n1p3.device 608ms [email protected]:intel_backlight.service 539ms snap-core-7270.mount 504ms snap-midori-451.mount 463ms snap-screencloud-1.mount 446ms snapd.seeded.service 440ms snap-gtk\x2dcommon\x2dthemes-1313.mount 420ms snap-core18-1066.mount 416ms snap-scrcpy-133.mount 412ms snap-gnome\x2dcharacters-296.mount
Please keep in mind that the services run in parallel.
Bonus Tip: Improving boot time
If you look at this output, you can see that both network manager and plymouth take a huge bunch of boot time.
Plymouth is responsible for that boot splash screen you see before the login screen in Ubuntu and other distributions. Network manager is responsible for the internet connection and may be turned off to speed up boot time. Don’t worry, once you log in, you’ll have wifi working normally.
sudo systemctl disable NetworkManager-wait-online.service
If you want to revert the change, you can use this command:
sudo systemctl enable NetworkManager-wait-online.service
Now, please don’t go disabling various services on your own without knowing what it is used for. It may have dangerous consequences.
Now that you know how to check the boot time of your Linux system, why not share your system’s boot time in the comment section?
Linux Uptime Command
Any Linux distro comes with the “uptime” command. It’s an important command for system administrators to know. It helps troubleshoot the issues related to power and scheduling. Of course, there are other alternative tools available for this purpose but uptime is relatively simple and easy to use.
The content of this guide is as follows:
Let’s start the uptime command.
How Does the Uptime Command Work?
If you use the system’s uptime command via command prompt, you get many benefits out of it. For example, suppose you are facing a problem in connecting to the server. Then, you can easily run the uptime command on the server to check if there has been a recent reboot on the server. This helps in troubleshooting the situation and provides you with better visibility to apply the required solution.
The output specifies the current time. “Up” specifies that the system is up and running along with the total time that the system is up to the user count and the system load averages.
Running the uptime command of a Linux system via the command line, you get a specified output in the following order:
- The current time of the system.
- The total uptime of the system.
- The active users that are currently running the system.
- The average of the system loads that is available for the past 1, 5, and 15 minutes.
Uptime command comes with various options. To check the options, we can run the “help” command.
Example 1: Uptime in Human-Readable Format
With the use of the “-p” option, you can get a pretty clear output which displays the uptime in the number of days, hours, minutes, and seconds format:
Example 2: Check the Start Time of the System
Another option is to check the exact time when the system is first started rather than the time spent since it started. Run the following command on the command-line interface with the “-s” option:
Example 3: Check the Version of the Installed Uptime Command
If you want to check the version of the installed uptime package in the system, run the following command with the “-V” option:
The output shows the current version of the “uptime” command.
Conclusion
Linux is a well-known environment and is highly recommended for various projects due to its stability and various configurations. The “uptime” command checks the system information. We explained the “uptime” command with its various options.
About the author
Syed Minhal Abbas
I hold a master’s degree in computer science and work as an academic researcher. I am eager to read about new technologies and share them with the rest of the world.
start time of a process on linux
How to find a process start time on ubuntu linux machine using c language. In linux there is /proc/[pid]/stat file which give information starttime %lu /*The time in jiffies the process started after system boot*/
and file /proc/stat that gives
btime %lu /*measurement of system boot time since Epoch in seconds*/
For adding both these values how can I convert former value into seconds because it is in jiffies unit.
1 Answer 1
Jiffies per second is configurable when one compiles the Linux kernel.
The following program uses the number of jiffies per second on the kernel you’re running. It takes an optional command line parameter, which is the process number. The default is the process number of the running program itself. Each second, it outputs the start time of the specified process, both as local time and UTC. The only reason for the repeat loop is to demonstrate that the value doesn’t change.
#include #include #include #include #include #include #include #include int find_nth_space(char *search_buffer, int space_ordinality ) < int jndex; int space_count; space_count=0; for(jndex=0; search_buffer[jndex]; jndex++ ) < if(search_buffer[jndex]==' ') < space_count++; if(space_count>=space_ordinality) < return jndex; >> > fprintf(stderr,"looking for too many spaces\n"); exit(1); > /* find_nth_space() */ int main(int argc, char **argv ) < int field_begin; int stat_fd; char proc_buf[80]; char stat_buf[2048]; long jiffies_per_second; long long boot_time_since_epoch; long long process_start_time_since_boot; time_t process_start_time_since_epoch; ssize_t read_result; struct tm gm_buf; struct tm local_buf; jiffies_per_second=sysconf(_SC_CLK_TCK); if(argc<2) < strcpy(proc_buf,"/proc/self/stat"); >else < sprintf(proc_buf,"/proc/%ld/stat",strtol(argv[1],NULL,0)); >for(;;) < stat_fd=open(proc_buf,O_RDONLY); if(stat_fd<0) < fprintf(stderr,"open() fail\n"); exit(1); >read_result=read(stat_fd,stat_buf,sizeof(stat_buf)); if(read_result <0) < fprintf(stderr,"read() fail\n"); exit(1); >if(read_result>=sizeof(stat_buf)) < fprintf(stderr,"stat_buf is too small\n"); exit(1); >field_begin=find_nth_space(stat_buf,21)+1; stat_buf[find_nth_space(stat_buf,22)]=0; sscanf(stat_buf+field_begin,"%llu",&process_start_time_since_boot); close(stat_fd); stat_fd=open("/proc/stat",O_RDONLY); if(stat_fd <0) < fprintf(stderr,"open() fail\n"); exit(1); >read_result=read(stat_fd,stat_buf,sizeof(stat_buf)); if(read_result <0) < fprintf(stderr,"read() fail\n"); exit(1); >if(read_result>=sizeof(stat_buf)) < fprintf(stderr,"stat_buf is too small\n"); exit(1); >close(stat_fd); field_begin=strstr(stat_buf,"btime ")-stat_buf+6; sscanf(stat_buf+field_begin,"%llu",&boot_time_since_epoch); process_start_time_since_epoch = boot_time_since_epoch+process_start_time_since_boot/jiffies_per_second; localtime_r(&process_start_time_since_epoch,&local_buf); gmtime_r (&process_start_time_since_epoch,&gm_buf ); printf("local time: %02d:%02d:%02d\n", local_buf.tm_hour, local_buf.tm_min, local_buf.tm_sec ); printf("UTC: %02d:%02d:%02d\n", gm_buf.tm_hour, gm_buf.tm_min, gm_buf.tm_sec ); sleep(1); > return 0; > /* main() */
How to determine boot time?
I am just curious to know the time taken by my system to boot. In Arch Linux there is something like systemd-analyze . What is the alternative in Ubuntu?
systemd is available since 15.10 version, 14.04 still relies on upstart. So you may use that command in versions 15.10 and up
+1 because I see this as a better question and more clear than similarly existing one; Existing question had zero votes and its answers are either incomplete or not useful.
4 Answers 4
Right after boot, run dmesg command. It shows you what you want.
Yes, except dmesg may contain other messages, for example I have in my dmesg right now a line dated [ 6467.1448 ] which is about 100 minutes after my boot. Point is that dmesg not meant specifically for boot. In between the system ready and user logging in, there may be extra message which wont tell reliable amount of time system booted
Without installing any software, you can use uptime , a native linux command, which serves to show how long computer has been running. The uptime command executed right after you boot the system will give you a general idea. However, it will take you extra seconds to enter password and login. Better approach would be to set calling uptime > /opt/BOOT.txt as part of lightdm startup script. It will be executed once the login screen shows up.
To do that , open or create /etc/lightdm/lightdm.conf file with root permissions.
It should contain the following lines:
[SeatDefaults] greeter-setup-script=uptime > /opt/BOOT.txt
After your next reboot there will be file /opt/BOOT.txt which will tell you how long system has been up.
Alternatively you could read /proc/uptime where the first entry is uptime in seconds